graham23s Posted November 26, 2007 Share Posted November 26, 2007 Hi Guys, i think i have found a way to piece together a search query using a plain form, if the user select "Search All" which has the value 0 i do this: <?php ## gender options ################################################# if($gender == 'M' || $gender =='F') { $searchquery .= "WHERE `gender`='$gender' "; } elseif($gender == 0) { // do nothing with the query } ## gender options ################################################# ?> what i'm wondering is, if this would work for all the fields, if it's X then search X from the database else carry on (ie select all) just curious before i do a lot of editing that might not work. cheers guys Graham Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 26, 2007 Share Posted November 26, 2007 Yes, you are doing it correctly...just to make sure, here is an example. <?php $query = "SELECT col FROM table WHERE"; if (isset($gender)) $query .= " AND gender='$gender'"; if (isset($country)) $query .= " AND country='$country'"; //...and so on ?> Quote Link to comment Share on other sites More sharing options...
graham23s Posted November 27, 2007 Author Share Posted November 27, 2007 Hi Poco, ah yeah the isset so instead of if($gender == 'M' || $gender =='F') { $searchquery .= "WHERE `gender`='$gender' "; } elseif($gender == 0) { // do nothing } i could do if(isset($var)) { // query here etc } thanks mate Graham Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.