Jaguar Posted July 24, 2007 Share Posted July 24, 2007 Say my database has a field, description, with the phrase "hello there" in it. When I do a search I want to match "hello there" and "there hello". Is the only way to do it like this? SELECT * FROM table WHERE description LIKE '%hello%' AND description LIKE '%there%'; Link to comment https://forums.phpfreaks.com/topic/61552-match-text-regardless-of-order/ Share on other sites More sharing options...
Jaguar Posted July 24, 2007 Author Share Posted July 24, 2007 Well I got working like that. Kind of anonying. Is there a better way? $search = mysql_escape_string($_GET['search']); $sql = str_replace(' ', "%' AND description LIKE '%", $search); $sql = "description LIKE '%" . $sql . "%'"; $result = mysql_query("SELECT * FROM table WHERE $sql"); Link to comment https://forums.phpfreaks.com/topic/61552-match-text-regardless-of-order/#findComment-306345 Share on other sites More sharing options...
fenway Posted July 30, 2007 Share Posted July 30, 2007 You could use a FULLTEXT index on this column. Link to comment https://forums.phpfreaks.com/topic/61552-match-text-regardless-of-order/#findComment-311114 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.