You don't need to "re-fetch" the usergroup ids, it's already there...
PHP Code:
$usergroupids = $vbulletin->userinfo['usergroupid'];
if (!empty($vbulletin->userinfo['membergroupids']))
{
$usergroupids .= ',' . $vbulletin->userinfo['membergroupids'];
}
$usergroups = $vbulletin->db->query_read("
SELECT *
FROM " . TABLE_PREFIX . "usergroup
WHERE usergroupid IN ($usergroupids)
");
while ($usergroup = $vbulletin->db->fetch_array($usergroups))
{
// some stuff
}