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 Link to comment https://forums.phpfreaks.com/topic/201860-sql-commas-seperated/ Share on other sites More sharing options...
Canman2005 Posted May 15, 2010 Author Share Posted May 15, 2010 Fixed it Link to comment https://forums.phpfreaks.com/topic/201860-sql-commas-seperated/#findComment-1058747 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.