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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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