MyBB Community Forums

Full Version: Board/Member Stats?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Is there a way to "count" how many accounts are in each group and show it on a page, similar to this?

Click here for image!

From what I remember, it would have to be a custom written PHP file but I'm not sure where to start.
Moved to Plugin Development.
well, i made it in 5 minutes, take a look on this code (Screenshot):

PS: Please note this code isn't looking for "Additional usergroups".

<?php

define("IN_MYBB", 1);
require_once "./global.php";

/* COUNTING HOW MUCH TIMES KEYS ARE REPEATED */

$query = $db->query("SELECT `usergroup` FROM `".TABLE_PREFIX."users`");

while($row = $db->fetch_array($query)) {
	$list_id[] .= $row['usergroup'];
}

$counted_groups = array_count_values($list_id);

/* SELECTING USERGROUPS */

$query = $db->query("SELECT `gid`, `title`, `description` FROM `".TABLE_PREFIX."usergroups`");

echo "<table border='1'>";

while($usergroups = $db->fetch_array($query)) {
	echo "<tr>";
	echo "<td style='padding:5px;'>";
	echo $usergroups['title']."<br>";
	echo $usergroups['description'];
	echo "</td>";
	echo "<td style='padding:5px;'>";
	echo (int)$counted_groups[$usergroups['gid']]." users";
	echo "</td>";
	echo "</tr>";
}

echo "</table>";


?>
OMG thank you!!! Is there a way to set it up to look for those additional user groups??
(2014-08-08, 08:16 PM)jesuite Wrote: [ -> ]OMG thank you!!! Is there a way to set it up to look for those additional user groups??

We'll see Toungue

2 minutes later:

Did it, and made a filter for usergroups that doesn't have users on it.

<?php

define("IN_MYBB", 1);
require_once "./global.php";

/* COUNTING HOW MUCH TIMES KEYS ARE REPEATED */

$query = $db->query("SELECT `usergroup`, `additionalgroups` FROM `".TABLE_PREFIX."users`");

while($row = $db->fetch_array($query)) {
    $list_id[] .= $row['usergroup'];

    /* ADDITIONAL USERGROUPS */
    if($row['additionalgroups'] != NULL) {
        $explode = explode(",", $row['additionalgroups']);
        if(!is_array($explode)) {
            $list_id[] = $row['additionalgroups'];
        } else {
            foreach($explode as $additionalgroups) {
                $list_id[] = $additionalgroups;
            }
        }
    }

}

$counted_groups = array_count_values($list_id);

/* SELECTING USERGROUPS */

$query = $db->query("SELECT `gid`, `title`, `description` FROM `".TABLE_PREFIX."usergroups`");

echo "<table border='1'>";

while($usergroups = $db->fetch_array($query)) {
    if($counted_groups[$usergroups['gid']] != 0) { //Removed groups that doesn't have users on it!
        echo "<tr>";
        echo "<td style='padding:5px;'>";
        echo $usergroups['title']."<br>";
        echo $usergroups['description'];
        echo "</td>";
        echo "<td style='padding:5px;'>";
        echo (int)$counted_groups[$usergroups['gid']]." users";
        echo "</td>";
        echo "</tr>";
    }
}

echo "</table>";


?>
Oh my goodness! This is amazing.

Is there anyway to select which usergroup ID's this code pulls? Say I want to show GID's 2, 4 & 5, but not groups 1 and 3?

Also... is there anyway to pull in custom profile fields? For instance. If I have a custom dropdown on my forum where users can select Male or Female in their character profiles. Is there any way to count how many Males and Females there are within a group?
(2014-08-08, 08:52 PM)Yaz Wrote: [ -> ]Oh my goodness! This is amazing.

Is there anyway to select which usergroup ID's this code pulls? Say I want to show GID's 2, 4 & 5, but not groups 1 and 3?

Also... is there anyway to pull in custom profile fields? For instance. If I have a custom dropdown on my forum where users can select Male or Female in their character profiles. Is there any way to count how many Males and Females there are within a group?


1. Yes, you can change if($counted_groups[$usergroups['gid']] != 0) to if(in_array($usergroups['gid'], array("2", "4", "5")))

2. Will check better, should be simple
$list_id[] .= $row['usergroup'];

'.=' hum, what?
(2014-08-09, 05:03 AM)Omar G. Wrote: [ -> ]
$list_id[] .= $row['usergroup'];

'.=' hum, what?

should me = ... idk why i typed .= O.o
and i missed $list_id = array(); too

But it worked xD

Edit: my 100th post Big Grin
Using [] after the variable name automatically makes it an array. If left blank it will start at 0 for the key and increment by 1 each time.
Pages: 1 2 3