if i'm reading right, you could use a join to get all of that info.
select users.group_id, user_id, user_name, groups.group_name from users
inner join groups on (groups.group_id = users.group_id) group by
parens not needed, it just makes it more legible.
that should give you an array, if used with mysql_fetch_array of:
group_id - user_id - user_name - group_name -
1 1 Tom Blue
1 2 Nancy Blue
1 3 Jim Blue
2 4 Bob Red
<randy.rankin@inv To: [EMAIL PROTECTED]
Subject: [PHP-DB] Confused
I have two MySQL tables, groups and users:
groups: group_id, group_name
users: user_id, user_name, group_id, etc.
I would like to produce one table for each group which will list all the
members for that particular group. For example:
Blue (group_id 1)
Tom (group_id 1)
Nancy (group_id 1)
Jim (group_id 1)
Red (group_id 2)
Bob (group_id 1)
Susan (group_id 1)
James (group_id 1)
My question is, do I need to run 2 queries? The first to select all the
groups and the second to select all the users in each group based on the
group_id? How would I loop through to create a table for each group?
Thanks inadvance for any help.
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php