Re: [PHP-DB] MySQL Search problem

2002-04-11 Thread Tatang Widyanto


>> $query = "SELECT * FROM Players WHERE Player LIKE '%$player_nameA%' OR Player LIKE
 '%$player_nameB%' OR College LIKE '%$college%' OR Draft_Year LIKE '%$year_drafted%' OR
 Round_Drafted LIKE '%$round_drafted%' OR Position LIKE '%$position%' OR
 Years_Team_Search LIKE '%$year_team%' OR Uniform_Number LIKE '%$uniform%' ORDER BY
 Player_ID" 

I think the problem was occured when one of your criteria is empty. 
It makes all records will dislayed. If criteria is "%%" all records will displayed.

Suggestion :

.

if ($player_nameA) $query = "OR Player LIKE  '%$player_nameA%' ";
if ($player_nameB) $query .= "OR Player LIKE  '%$player_nameB%' ";
if ($college) $query .= "OR College LIKE  '%$college%' ";
if ($year_drafted) $query .= "OR Draft_Year LIKE  '%$year_drafted%' ";
if ($round_drafted) $query .= "OR Round_Drafted LIKE  '%$round_drafted%' ";
if ($position) $query .= "OR Position LIKE  '%$postition%' ";
if ($year_team) $query .= "OR Year_Team_Search LIKE  '%$year_team%' ";
if ($uniform) $query .= "OR Uniform_Number LIKE  '%$uniform%' ";

$query = substr($query,3);  // strip first OR.
$query = "SELECT * FROM Players WHERE $query ORDER BY Player_ID";

.

deZayner




 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] MySQL Search problem

2002-04-10 Thread Terry Huffman

Can anyone tell me what is wrong with the code that is below?  Whenever I use this it 
returns all the records in the table no matter what is searched for.

Thanks for any help,

Terry

-- CODE 

Search results:";

echo "";

do {

echo "".$myrow["Player"]."";

} while ($myrow=mysql_fetch_array($result)); // start loop over to output more because 
$myrow was set again

echo "";

?>

- END CODE --

--- FORM 









Players First Name









Players Last Name









College









Year Drafted 

Any

1968

1969

1970

1971

1972

1973

1974

1975

1976

1977

1978

1979

1980

1981

1982

1983

1984

1985

1986

1987

1988

1989

1990

1991

1992

1993

1994

1995

1996

1997

1998

1999

2000

2001

2002









Round Drafted 









Position

Any

Offense

Defense

Special Teams











Year With the team

Any

1968

1969

1970

1971

1972

1973

1974

1975

1976

1977

1978

1979

1980

1981

1982

1983

1984

1985

1986

1987

1988

1989

1990

1991

1992

1993

1994

1995

1996

1997

1998

1999

2000

2001

2002











Uniform Number