Canman2005 Posted May 15, 2010 Share Posted May 15, 2010 Hi all I have the following QUERY SELECT * FROM `products` WHERE ((`title` LIKE '%Apple%') || (`title` LIKE '%Google%') || (`title` LIKE '%Microsoft%')) Which all works super. But I am adding a form onto the front end which allows people to enter a "keyword" into a form field, I am asking them to seperate keywords with commas, when they submit the form, it will create a variable called $words so that value could be something like $words = "apple, microsoft, google, ebay"; or $words = "iphone, ipod"; my question is, how can I get PHP to turn that variable into something like ((`title` LIKE '%Apple%') || (`title` LIKE '%Google%') || (`title` LIKE '%Microsoft%')) so that I can use it within my query. I did have a thought though, and that was about people adding a comma at the start or end, so the variable could look like $words = ",iphone, ipod"; or $words = "iphone, ipod,"; or $words = ",iphone, ipod,"; So I guess I would need to strip any spaces and commas at the start and end of the variable I have been trying something like str_replace(',','%') || (`title` LIKE '%',$words); but I cannot seem to tweak it so that it works correctly Anyone have any ideas? Maybe my way is going to be too complex Thanks Dave Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted May 15, 2010 Author Share Posted May 15, 2010 Fixed it 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.