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 Link to comment https://forums.phpfreaks.com/topic/284346-search-by-key-word/ Share on other sites More sharing options...
Psycho Posted November 28, 2013 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); Link to comment https://forums.phpfreaks.com/topic/284346-search-by-key-word/#findComment-1460462 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. . Link to comment https://forums.phpfreaks.com/topic/284346-search-by-key-word/#findComment-1460474 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.