Attilitus
08-06-2007, 07:18 PM
Is there any easy way to retrieve the amount of users who have a specific secondary usergroup? I need to be able to quickly retrieve a count, and want to know the most load-friendly way of doing it. (Without looping through the resultset to check if the groupid is in the array of membergroupids.)
Edit: for other people's reference here is how vbulletin does it:
(I guess I'm all set.)
// count secondary users
$groupcounts = $db->query_read("
SELECT membergroupids, usergroupid
FROM " . TABLE_PREFIX . "user
WHERE membergroupids <> ''
");
while ($groupcount = $db->fetch_array($groupcounts))
{
$ids = fetch_membergroupids_array($groupcount, false);
foreach ($ids AS $index => $value)
{
if ($groupcount['usergroupid'] != $value AND !empty($vbulletin->usergroupcache["$value"]))
{
$vbulletin->usergroupcache["$value"]['secondarycount']++;
}
}
}
Edit: for other people's reference here is how vbulletin does it:
(I guess I'm all set.)
// count secondary users
$groupcounts = $db->query_read("
SELECT membergroupids, usergroupid
FROM " . TABLE_PREFIX . "user
WHERE membergroupids <> ''
");
while ($groupcount = $db->fetch_array($groupcounts))
{
$ids = fetch_membergroupids_array($groupcount, false);
foreach ($ids AS $index => $value)
{
if ($groupcount['usergroupid'] != $value AND !empty($vbulletin->usergroupcache["$value"]))
{
$vbulletin->usergroupcache["$value"]['secondarycount']++;
}
}
}