essjay_d12 Posted May 30, 2006 Share Posted May 30, 2006 Hi, I have a database that stores shopper information , and the items they purchased. I would like PHP to split table value (seperating using the ' ,') then somehow put it back into the select statement. The Scenario below explains it more clearly.[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]e.g. Shopper DatabaseName - Julie JonesItems - Banana, Cereal, Bread, MilkName - David BallItems - Beer, Milk[/quote]It varies to how many items they have (based on how many they add into the field)I now want to (say Julie is logged in [but the code needs to be for whoever is logged in]) to list all the shops that have ANY of those ingredients (so not necessarilly all)[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]e.g Superstore DatabaseSuperstore_Name - TescoSuperstore_Items - Milk, BreadSuperstore_Name - Corner ShopSuperstore_Items - CerealSuperstore_Name - SaindsburysSuperstore_Items - Coffee[/quote]So I want to say (Julie being logged in).....SELECT Superstore_Name FROM Superstore WHERE Superstore_Items LIKE 'Banana' OR Superstore_Items LIKE 'Cereal' OR Superstore_Items LIKE ' OR Superstore_Items LIKE ' 'Bread' OR Superstore_Items LIKE 'Milk'.........In other words PHP needs to split the table value (seperating using the ' ,') then somehow put it back into the select statement. Please can someone help?Thanksd Quote Link to comment https://forums.phpfreaks.com/topic/10780-expert-php-coding-help-needed/ Share on other sites More sharing options...
poirot Posted May 30, 2006 Share Posted May 30, 2006 You can use explode(',' $variable);[a href=\"http://www.php.net/explode\" target=\"_blank\"]http://www.php.net/explode[/a] Quote Link to comment https://forums.phpfreaks.com/topic/10780-expert-php-coding-help-needed/#findComment-40284 Share on other sites More sharing options...
essjay_d12 Posted May 30, 2006 Author Share Posted May 30, 2006 ok that would explain how to seperate them, but what about understanding how many have been seperated? in order to have a count for a loop , which would then insert each seperated item into the sql query. Are they saved as an array?How would I go about doing this?ThanksD Quote Link to comment https://forums.phpfreaks.com/topic/10780-expert-php-coding-help-needed/#findComment-40288 Share on other sites More sharing options...
Honoré Posted May 30, 2006 Share Posted May 30, 2006 Yes they are stored in an array as you can read here : [a href=\"http://www.php.net/explode\" target=\"_blank\"]http://www.php.net/explode[/a] Quote Link to comment https://forums.phpfreaks.com/topic/10780-expert-php-coding-help-needed/#findComment-40289 Share on other sites More sharing options...
ludwigvb Posted May 30, 2006 Share Posted May 30, 2006 [!--quoteo(post=378423:date=May 30 2006, 07:21 PM:name=Essjay_d12)--][div class=\'quotetop\']QUOTE(Essjay_d12 @ May 30 2006, 07:21 PM) [snapback]378423[/snapback][/div][div class=\'quotemain\'][!--quotec--]ok that would explain how to seperate them, but what about understanding how many have been seperated? in order to have a count for a loop , which would then insert each seperated item into the sql query. Are they saved as an array?How would I go about doing this?ThanksD[/quote]Maybe this can help:[a href=\"http://www.phpfreaks.com/quickcode/Building-a-Dynamic-Form-Select-Menu/2.php\" target=\"_blank\"]http://www.phpfreaks.com/quickcode/Buildin...lect-Menu/2.php[/a] Quote Link to comment https://forums.phpfreaks.com/topic/10780-expert-php-coding-help-needed/#findComment-40301 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.