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 Link to comment https://forums.phpfreaks.com/topic/79000-search-form-code/ 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 ?> Link to comment https://forums.phpfreaks.com/topic/79000-search-form-code/#findComment-399764 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 Link to comment https://forums.phpfreaks.com/topic/79000-search-form-code/#findComment-400444 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.