Jump to content


Photo

Expert PHP Coding help needed


  • Please log in to reply
4 replies to this topic

#1 essjay_d12

essjay_d12
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts

Posted 30 May 2006 - 03:56 PM

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 Database

Name - Julie Jones
Items - Banana, Cereal, Bread, Milk

Name - David Ball
Items - 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 Database

Superstore_Name - Tesco
Superstore_Items - Milk, Bread


Superstore_Name - Corner Shop
Superstore_Items - Cereal


Superstore_Name - Saindsburys
Superstore_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?

Thanks

d

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 30 May 2006 - 04:07 PM

You can use explode(',' $variable);
[a href=\"http://www.php.net/explode\" target=\"_blank\"]http://www.php.net/explode[/a]
~ D Kuang

#3 essjay_d12

essjay_d12
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts

Posted 30 May 2006 - 04:21 PM

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?

Thanks

D

#4 Honoré

Honoré
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationAntwerp - Belgium

Posted 30 May 2006 - 04:27 PM

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]

#5 ludwigvb

ludwigvb
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 30 May 2006 - 05:10 PM

[!--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) View Post[/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?

Thanks

D
[/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]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users