Re: Confused
| From: | Jeffrey_N_Dyke at Keane dot com | Date: | Mon, 23 Sep 2002 11:47:02 +0000 |
| Subject: | Re: Confused | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-21931@lists.php.net to get a copy of this message | ||
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
users.group_id
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
etc.....
jd
"Rankin, Randy"
<randy.rankin@inv To: php-db@lists.php.net
ensys.com> cc:
Subject: [PHP-DB] Confused
09/23/2002 07:38
AM
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.
Randy Rankin