Oh, right, I see now. So I guess a user could be displayed in two sections if they happened to be in more than one of those groups. So I guess you're right, ORDER BY wouldn't help.
But I think you can do the array thing with one query. Something like:
Code:
while($roster = $db->fetch_array($result)) {
$ids = explode(',',$roster['membergroupids']);
$ids[] = $roster['usergroupid'];
foreach ($ids AS $id) {
$rostergroups[$id][] = &$roster;
}
}
foreach($displaygroups AS $groupid) {
printf("Group: %s<br \>", $groupid);
if (!is_array($rostergroups[$groupid])) continue;
foreach ($rostergroups[$groupid] AS &$roster) {
printf("Username: %s<br \>", $roster['username']);
$charinfo['count']++;
}
}
(I haven't tried this at all, so it could be wrong).