Jump to content

SQL Search Functionality


wchamber22

Recommended Posts

Hi gents,

 

This will be an easy one for you all! I have a sql select statement and everything functions fine as is, BUT I would like to give users more freedom.

 

Using this sql statement the results only return if the user types the Botanical Name or Common Name of a particular plant exactly as it is spelled in the database:

 

$sql = mysql_query("SELECT PlantID, CommonName FROM plants WHERE BotanicalName='$BotanicalName' OR CommonName='$CommonName' OR Use1='$Use' OR Use2='$Use' OR Use3='$Use' OR Use4='$Use' OR Use5='$Use' ORDER BY CommonName");

 

What if the user doesn't know the species of a plant and only it's genus or the user only knows Maple tree and not which particular one they are looking for:

 

For example:

Plant in Database = Brandywine Red Maple

User Search would have to be exactly that "Brandywine Red Maple" for a result to return

Ideally I would like the user to be able to type in "Maple" and ALL Maples return

 

Let me know if you need more info

Link to comment
Share on other sites

Hi Zurev,

 

I tried the LIKE statement as you described and still no success, again here is my SQL to this point.

 

$sql = mysql_query("SELECT PlantID, CommonName FROM plants WHERE BotanicalName LIKE '%$BotanicalName%' OR CommonName LIKE '%$CommonName%' OR Use1='$Use' OR Use2='$Use' OR Use3='$Use' OR Use4='$Use' OR Use5='$Use' ORDER BY CommonName");

 

This sql statement now returns ALL the fields in the database when searching for anything.

 

Thanks, again.

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.