Jump to content

[SOLVED] Whats wrong with my query!!!!???? Searching in MySql


Recommended Posts

Here is my query.

 

 $query = "SELECT w1.* FROM wine w1, winery w2 " .
           "WHERE w1.winery_id = w2.winery_id AND w2.winery_name = '$wineryName' AND w1.wine_name=' ".$search." ' ";

This code works fine. It tries to find the wine name that is exactly the search term.

 

 

 

Now i try to use the % signs to suggest anything that includes the search term.

 

 $query = "SELECT w1.* FROM wine w1, winery w2 " .
           "WHERE w1.winery_id = w2.winery_id AND w2.winery_name = '$wineryName' AND w1.wine_name=' %".$search." %' ";

 

This code doesn't work.

 

question: I took this directly out of a book so could it be that my web host has a different version of mysql than my college? Did the % sign for mysql querys come out in a later version?

The percent sign type of search only works with the "LIKE" keyword and not an equal sign (=).

 

 

http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like

 

 

FYI - In your first query, you have space after the single quotes - should take them out.

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.