Jonob Posted June 9, 2009 Share Posted June 9, 2009 I have a table with something like the following structure: id (PK) search_term (varchar 15) What I would like to do is find all occurences of matching search_term. For example, lets assume that I have the following records: id, search_term 1, Maple 2, Oak 3, Elm What I would like to do is pass in something like "Red Maple Tree", and it would return 1, Maple Or "Oak roots" would return 2, Oak Or "El" would return null I have tried SELECT id, search_term FROM import_rule WHERE %search% LIKE "Red Maple Tree" but this obviously fails. Any help greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/161493-solved-like-clause/ Share on other sites More sharing options...
fenway Posted June 9, 2009 Share Posted June 9, 2009 You'd have to split your search query on, say, spaces, and then test each keyword separately. Quote Link to comment https://forums.phpfreaks.com/topic/161493-solved-like-clause/#findComment-852227 Share on other sites More sharing options...
Jonob Posted June 9, 2009 Author Share Posted June 9, 2009 OK, gotcha. I exploded the search term into an array in php, and created my WHERE statement using each value in the array. i.e. WHERE (seach_term LIKE '%Red%' OR seach_term LIKE '%Maple%' OR seach_term LIKE '%Tree%') Works perfectly, thanks Fenway Quote Link to comment https://forums.phpfreaks.com/topic/161493-solved-like-clause/#findComment-852285 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.