Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Storing multiple matches as subarray where tables join together



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

5+ Year Member

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.



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

10+ Year Member


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.


Featured Threads

Hot Threads This Week

Hot Threads This Month