lilmer Posted November 28, 2013 Share Posted November 28, 2013 I've got this data. - - - - - - - - - - - - - | ID | content | - - - - - - - - - - - - - | 1 | Hand Some | - - - - - - - - - - - - - | 2 | Big Apple | - - - - - - - - - - - - - | 3 | Green Day | - - - - - - - - - - - - - If I search data by "Some Hand", then it must show "Hand Some" cause it is on the list. I've try LIKE "%variable%" but it since it still only search for specific keyword that will match the data on a field. Can you please give an idea on what is the best way to filter data with my example Quote Link to comment Share on other sites More sharing options...
Solution Psycho Posted November 28, 2013 Solution Share Posted November 28, 2013 You can use Full Text searching - preferred method. This involves more than I would be willing to try and explain in a forum post. there are plenty of tutorials out there you can look up. Or, you can roll your own. Take the input and split it by spaces, then use those values to build the query. $searchString = $_POST['search_string']; $searchWords = array_filter(explode(' ', $searchString)); $WHERE_PARTS = array(); foreach($searchWords as $word) { $WHERE_PARTS[] = "content LIKE '%{$word}%'"; } $query = "SELECT * FROM table_name WHERE " . implode (' AND ', $WHERE_PARTS); Quote Link to comment Share on other sites More sharing options...
lilmer Posted November 28, 2013 Author Share Posted November 28, 2013 This is what I'm looking for. Thank you. . You're a developer and a Psychic. . 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.