homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

Storing multiple matches as subarray where tables join together

5+ Year Member

Msg#: 3309663 posted 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

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.




5+ Year Member

Msg#: 3309663 posted 12:52 am on Apr 13, 2007 (gmt 0)


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