eRott Posted July 20, 2007 Share Posted July 20, 2007 Hi, Ok, I have a database with a table named phone. Inside that table i have 4 fields: fname lname ext dept I was wondering, how would I go about searching all of the 4 fields at the same time? I have a drop down list that allows a user to search specific fields, one of the above. However, I would also like to add an ALL option where it would search ALL of them. Here is an example of the code i currently use: ........ if($stype == "fname"){ $data = mysql_query("SELECT * FROM phone WHERE firstname LIKE'%$find%'"); } else if($stype == "lname"){ $data = mysql_query("SELECT * FROM phone WHERE lastname LIKE'%$find%'"); } ..... Thanks! Link to comment https://forums.phpfreaks.com/topic/60972-multiple-parameter-search/ Share on other sites More sharing options...
Wildbug Posted July 20, 2007 Share Posted July 20, 2007 .... elseif ($stype == "ALL") { $data = mysql_query("SELECT * FROM phone WHERE firstname LIKE '%$find%' OR lastname LIKE '%$find%' LIKE ext = '%$find%' OR dept LIKE '%$find%'"); }.... That's not very sophisticated, but you just need to add some ORs. You could have multiple search boxes instead of just the one "$find" field. You could split it up via spaces and only put numbers into the "ext" search condition.... whatever. Link to comment https://forums.phpfreaks.com/topic/60972-multiple-parameter-search/#findComment-303486 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.