Jump to content

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


snowman15

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.

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.