Jump to content

search query quistion


redarrow

Recommended Posts

What i need to no what is the best way to get a search feature that will let the database search using all
form boxs example, pulldown and input box

from my below code the database gets searched via the name and the word name comes from the varable name in the form input box,

so if you had lots of search features how do you add them example.

do you just add afther the WHERE clause other AND that relate to the input form name or the pulldown option name this is to save on querys or do you add lots and lots of querys.

example for 2 input boxs and 1 pulldown box
[code]
WHERE fname = '%"fname"%' AND address='%"address"%' AND price='%"price"'  
[/code]


seach example for 1 input box
[code]

//connect to database for data result useing like and %wildcard for name search

$db=mysql_connect("localhost","xxxx","xxxx");
mysql_select_db("xxxx" , $db);
$query="select pro_membersu.fname , pro_membersu.birthday , pro_membersu.email from pro_membersu where fname like '%".$name."%'";
$result=mysql_query($query);

[/code]
Link to comment
Share on other sites

I wonder if this would work?

$sql = "select `fname`, `birthday`, `email` from `pro_membersu` where `fname` like '%{$name}%' and `address` like '%{$address}%' and `price` like '%{$price}%';";

alternatively, if you just want to match when one or more conditions are found, then you could use or instead of and:

$sql = "select `fname`, `birthday`, `email` from `pro_membersu` where `fname` like '%{$name}%' or `address` like '%{$address}%' or `price` like '%{$price}%';";
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.