Jump to content

Multiple Parameter Search


eRott

Recommended Posts

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

.... 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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.