snowman15 Posted November 29, 2007 Share Posted November 29, 2007 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? Link to comment https://forums.phpfreaks.com/topic/79365-solved-whats-wrong-with-my-query-searching-in-mysql/ Share on other sites More sharing options...
toplay Posted November 29, 2007 Share Posted November 29, 2007 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. Link to comment https://forums.phpfreaks.com/topic/79365-solved-whats-wrong-with-my-query-searching-in-mysql/#findComment-401796 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.