ecopetition Posted September 26, 2008 Share Posted September 26, 2008 Hello, I'm trying to search a database with table X using the following query, where $search_query is the inputted search string and Y and Z are two columns. $sql = "SELECT * FROM X WHERE Y LIKE ($search_query) ORDER BY Z DESC"; This code works fine, but returns a result only when Y is EQUAL to the search query, rather than when Y only just includes the search query somewhere. Does anyone have a clue what's wrong or what I can do you fix this? Thanks, Peter Link to comment https://forums.phpfreaks.com/topic/125957-solved-searching-a-database/ Share on other sites More sharing options...
Push Eject Posted September 26, 2008 Share Posted September 26, 2008 $sql = "SELECT * FROM X WHERE Y LIKE '%$search_query%' ORDER BY Z DESC"; Link to comment https://forums.phpfreaks.com/topic/125957-solved-searching-a-database/#findComment-651330 Share on other sites More sharing options...
ecopetition Posted September 26, 2008 Author Share Posted September 26, 2008 Brilliant, thanks a lot. Link to comment https://forums.phpfreaks.com/topic/125957-solved-searching-a-database/#findComment-651342 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.