MyBB Community Forums

Full Version: Total Members of Group / Total Threads in FID
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Alright so I have made a thread in the past - link - I've ran into some issues along the ways. I've ran various MyBB SQL Queries and yet to no avail. Perhaps what I'm needing is a clean mind but I'm exhausted and getting rather annoyed. Any suggestions or results would be awesome in this case.

Problem Number One
Okay so for example I have a total of 5 administrators on my board.
I want to display the total members in each group like such.
Very similar to the overall forum statistics.

[Image: c7d303773032d4b1a76807c02bd45990.png]

Problem Number Two
Okay so for example I have a total of 3,000 threads in Forum ID 2.
I want to display the total threads in that Forum ID.
Very similar to the overall forum statistics.

[Image: d72a00b66dfc41ffef76292a51132e54.png]
The first one gets ugly if you are considering secondary usergroups. It gets to be very server intensive based on how many members you have. If you are only using primary groups you could do something like this:

$usergroupsquery = $db->simple_select("usergroups", "gid,title");
echo "<table><tr><th>Usergroup</th><th>Number of Users</th></tr>";
while($usergroup = $db->fetch_array($usergroupsquery))
$usercountquery = $db->simple_select("users", "COUNT(uid) as total", "usergroup=" . $uisergroup['gid']);
$count = $db->fetch_field($usercountquery, "total");
echo "<tr><td>" . $usergroup['title'] . "</td><td>" . $count . "</td></tr>";
echo "</table>";

I purposely avoided querying the user table only because otherwise you'd have to select the usergroup for each member and run it through a loop in php to get counts. That would lead to much more server intensive process.

The second problem can be handled similar to the first except you will first query the forums table and then the threads table.
(2016-11-26, 02:07 PM)dragonexpert Wrote: [ -> ]-snip

I managed to get the code reduced down to 2 lines. Thanks for the help. Before the output kept coming up blank but now I see where I was going wrong. Thanks dude.