
May 24th, 2003, 12:04 PM
|
|
Registered User
|
|
Join Date: Apr 2007
Posts: 22,309
Time spent in forums: < 1 sec
Reputation Power: 24
|
|
|
Selective database query variable use
Hi folks, I was wanting to create a MySQL database query where if a person enters a specific value in a box, that is passed to the query to search a field. In addition, if the person selects "all" from the box, I would like the query to change to select all rows from the field. Is there a simple way to do this?
One guy suggested something like this, but Im not sure how it works. Help appreciated, Doug
php Code:
Original
- php Code |
|
|
|
$query = "SELECT * FROM table1"; if ($field2 != "all") $constraint[] = "field2 = '$field2'" $query .= " WHERE " . join(" AND ", $constraint);
|