Log in

View Full Version : Usergroups


lasto
03-28-2008, 08:09 PM
Say i have 20 users in one usergroup - how can i call the amount of users in one specific usergroup so i can use that info on my index.php page.

I just want to grab the amount of users in one specific usergroup and display the info on main page so it looks something like this :

Admins : 7 (if that is the correct number)

Is this possible ......

--------------- Added 1206807835 at 1206807835 ---------------

anyone know a way to pull this off - i know its not a big request :)

lasto
03-30-2008, 06:46 AM
/me bumps this again

Opserty
03-30-2008, 11:33 AM
Check the Usergroup.php page in the AdminCP to see how vBulletin does it.

I'm not sure if the count is stored in the usergroup cache, (run a var_dump() of $vbulletin->usergroupcache to see if it is present).

If it doesn't then you best bet is to run a query to count the users in each usergroup and run this on the usergroup.php page or as a scheduled task to update a cache in the datastore. (You don't want to be querying the database on every page load when the data is going to be fairly static).

I'll see if I can give you some more information later, when I boot up my dev vBulletin, but this should give you an idea of what to do/look for.

lasto
03-30-2008, 04:37 PM
cheers m8 as all i want the code for is to call on index.php to show how many users are in one particular usergroup.

Opserty
03-30-2008, 05:15 PM
Hmm by the looks of it, it isn't stored in the usergroup cache. Here is the query I pulled from the usergroup admin page:

// count primary users
$groupcounts = $db->query_read("
SELECT user.usergroupid, COUNT(user.userid) AS total
FROM " . TABLE_PREFIX . "user AS user
LEFT JOIN " . TABLE_PREFIX . "usergroup AS usergroup USING (usergroupid)
WHERE usergroup.usergroupid IS NOT NULL
GROUP BY usergroupid
");

You could change the WHERE clause to select just what you want.

Have a read of this as you'll probably just want to cache the results to save on queries and processing time. Cache System Explanation (datastore) (https://vborg.vbsupport.ru/showthread.php?t=110628&highlight=datastore)

lasto
03-30-2008, 06:38 PM
bit to much for me m8 how can i use the above info to show the stat i want without it sounding to over complicated :)

and thanks as well

Dismounted
03-31-2008, 05:19 AM
The simple way, without using the cache (bad for load-heavy sites, and bad in general coding practise!):
// count users in usergroup 7 (primary usergroups only)
$groupcount = $vbulletin->db->query_read("
SELECT COUNT(userid)
FROM " . TABLE_PREFIX . "user
WHERE usergroupid = 7
");
$groupcount = $groupcount['userid'];

lasto
03-31-2008, 03:00 PM
i would add that code to my index.php is that correct : now what code would i need to call it into the board

Opserty
03-31-2008, 04:17 PM
Put that code in a FORUMHOME hook. Like forumhome_complete or something like that.

Then you just need to add $groupcount in your FORUMHOME template. Like:Adminstrator: $groupcount

lasto
04-01-2008, 03:51 AM
thanks m8 will try this tonight when get back from work.