RE: [PHP] Confused
| From: | M dot A dot Bond at open dot ac dot uk | Date: | Mon, 23 Sep 2002 12:58:59 +0000 |
| Subject: | RE: [PHP] Confused | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-117266@lists.php.net to get a copy of this message | ||
Nope,
Do a select like so:
Select user_name, group_name from users,groups where
users.group_id=groups_id order by group_name;
Then do a php loop (you'll need to find the eact php commands, this is just
an example):
While (!$results->EOF)
{
If ($results[group_name]!="$old_groupname")
{
$old_groupname=$results[group_name];
print
"<TR><TD>$old_groupname</td><td> </td></tr>";
}else
{
print
"<TR><TD> </td><TD>$results[user_name]</td></tr>";
}
$results=mysql_fetch_array($sql);
}
You'll obviously need to get exact mysql commands etc, and open and close
your table outside the loop, but this should be basically it.
Thanks
Mark
-----Original Message-----
From: Rankin, Randy [mailto:randy.rankin@invensys.com]
Sent: 23 September 2002 13:37
To: 'php-general@lists.php.net'
Subject: [PHP] 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 in advance for any help.
Randy Rankin