homepage Welcome to WebmasterWorld Guest from 54.161.166.171
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Storing multiple matches as subarray where tables join together
otem




msg:3309665
 6:46 pm on Apr 12, 2007 (gmt 0)

Is it possible, or even efficient to place into an array all matching data from where a table joins another table.

If allowed, I'm going to borrow the tables from this MySQL Join page I've been using as a tutorial: [tizag.com...]

family Table:
Position Age
Dad 41
Mom 45
Daughter 17
Dog

food Table:
Meal Position
Steak Dad
Salad Mom
Tacos Dad

You will get the following output with this command:

$result=mysql_query("SELECT * FROM family, food WHERE family.position=food.position ORDER BY family.position DESC");
while($data=mysql_fetch_array($result)) echo "<li>".$data["family.position"]." - ".$data["food.meal"]."</li>";

<li>Dad - Steak</li>
<li>Dad - Tacos</li>
<li>Mom - Salad</li>

I'm wondering however, if the corrisponding data in the food table can be stored as some kind of subarray, allowing me to output this kind of result:

<li>Dad - Steak, Tacos</li>
<li>Mom - Salad</li>

I've been trying to lookup information on the MySQL website and in books on campus, but I haven't found anything on this issue, which makes me wonder if I'm going in the wrong direction.

Thanks

 

FalseDawn




msg:3309907
 12:52 am on Apr 13, 2007 (gmt 0)

[4guysfromrolla.com...]

The example uses a UDF, but you may be able to do it in a subquery. The bottom line is, it's probably easier to do it in code than SQL.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved