Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old January 29th, 2003, 12:15 AM
Mic Mic is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 Mic User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
string to array then to convert into a matching name

Hi all,
Please help with this problem.
I want to retrieve a data from postgreSQL then
convert it with a specified name.
say I have a form inputting data.

<form>
<input type="checkbox" name="id[]" value="1">apple
<input type="checkbox" name="id[]" value="2">orange
<input type="checkbox" name="id[]" value="3">banana
</form>

table1:fruits
fruits_id fruits_name
1 apple
2 orange
3 banana

table2:list
list_id fruits_select(*varchar)
1 1
2 2
3 1 3
4 1 2 3

then, I want to show the list like this.
list_id fruits_name
1 apple
2 orange
3 apple banana
4 apple orange banana

Do I use preg_split to split the string into array then count the array length???
Thanks!!

Reply With Quote
  #2  
Old January 29th, 2003, 03:42 PM
NetproHosting NetproHosting is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apex, NC, USA
Posts: 31 NetproHosting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to NetproHosting
RE: string to array then to convert into a matching name

Hey Mic,

Looking at what you're trying to do, I am thinking the database schema could be modified to better support this. Sure it's possible to do what you want with the current setup (e.g. exploding the list records and then looking up the value, etc.), but I might suggest this instead...

You have a many-to-many relationship between fruit and lists e.g. apple appears in many lists, and each list can contain many fruit. So, the "typical" way to resolve a many-to-many relationship is to use an intermediate table. Your singular tables would then only contain information about the single items:

table1:fruits
fruits_id fruits_name
1 apple
2 orange
3 banana

table2:lists
list_id list_description
1 Apple Cup
2 Orange Cup
3 Lite Cocktail
4 Full Cocktail

Notice that fruits only talks about the core fruit items, and lists only talks about the list itself, not the fruit contained.

Then build this intermediate table:

table3: fruits_list
list_id fruit_id
1 1
2 2
3 1
3 3
4 1
4 2
4 3

With a schema like this, you can join the tables in a query and iterate over the fruits_list records to get your desired result.

Hope this helps.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > string to array then to convert into a matching name


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT