View Full Version : [RELEASE] Show number of users in each group
leadZERO
02-25-2001, 01:38 PM
Someone asked for this hack, it was a simple thing so I took 10 minutes and coded it.
This will show the number of users in each group in the User Groups and Permissions -> Modify
#### Changes to "admin/usergroup.php" ####
~ Search for:
while ($usergroup=$DB_site->fetch_array($usergroups)) {
~ Add after:
//LEADZERO -- number of users per group hack
//ADD BLOCK
$q_id = $DB_site->query("SELECT username FROM user WHERE usergroupid=$usergroup[usergroupid]");
$mems = $DB_site->num_rows( $q_id );
//END ADD BLOCK
~ Replace:
echo "<li>$usergroup[title]".
~ With:
//CHANGE LINE
//WAS - echo "<li>$usergroup[title]".
echo "<li>$usergroup[title] - <i>$mems Members</i>".
Nice one and valuable. Thanks for sharing it with us. I'll try it on my test board this evening. :)
May I suggest changing
//LEADZERO -- number of users per group hack
//ADD BLOCK
$q_id = $DB_site->query("SELECT username FROM user WHERE usergroupid=$usergroup[usergroupid]");
$mems = $DB_site->num_rows( $q_id );
//END ADD BLOCK
to
//LEADZERO -- number of users per group hack
//ADD BLOCK
$q_id = $DB_site->query_first("SELECT COUNT(*) as count FROM user WHERE usergroupid=$usergroup[usergroupid]");
$mems = $q_id[count];
//END ADD BLOCK
Will be a wee bit faster for ya..
Hmmm...
Are you sure thats right? I tried it and now it doesn't show the number...
Looks right to my naked eye but if ya want you can replace your whole block of code in the modify section of usergroup.php with the following code. It is what will be in beta3/release (whichever it is)
$usergroups=$DB_site->query("SELECT usergroup.usergroupid, usergroup.title, COUNT(user.userid) as count
FROM usergroup
LEFT JOIN user ON (user.usergroupid = usergroup.usergroupid)
GROUP BY usergroup.usergroupid
ORDER BY usergroup.title");
echo "<table align=\"center\" bgcolor=\"black\" border=0 cellpadding=0 cellspacing=0><tr><td>";
echo "<table border=0 cellspacing=1 cellpadding=4><tr bgcolor=\"#3F3849\"><td align=\"center\" colspan=4><FONT color=\"#BCB6CD\"><b>Usergroups</b></FONT></td></tr>\n";
echo "<tr bgcolor=\"#51485F\"><td nowrap align=\"center\" width=\"100%\"><FONT color=\"#BCB6CD\">Usergroup</font></td><td align=\"center\" nowrap><FONT color=\"#BCB6CD\"># of Users</font></td><td align=\"center\" nowrap><FONT color=\"#BCB6CD\">Edit</font></td><td nowrap align=\"center\"><FONT color=\"#BCB6CD\">List Users</font></td></tr>\n";
while ($usergroup=$DB_site->fetch_array($usergroups)) {
echo "<tr bgcolor=\"#CCCCCC\"><td width=\"100%\">$usergroup[title]</td><td nowrap>$usergroup[count]</td><td nowrap>".
makelinkcode("edit","usergroup.php?s=$session[sessionhash]&action=edit&usergroupid=$usergroup[usergroupid]").
iif($usergroup[usergroupid]>6,makelinkcode("remove","usergroup.php?s=$session[sessionhash]&action=remove&usergroupid=$usergroup[usergroupid]"),"")."</td><td nowrap>".
makelinkcode("list all users","user.php?s=$session[sessionhash]&action=find&usergroupid=$usergroup[usergroupid]").
"</td></tr>\n";
}
echo "</table></td></tr></table>\n";
I'm getting this error when I change it into that freddie:
: Using scalar variable $usergroup as an array or object in .. usergroup.php
fixed it... I forgot something :D
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.