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%'; Quote Link to comment 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"); Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.