MyBB Community Forums

Full Version: Usergroup Name
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Im trying to display a users usergroup name on the index. Eg: Admin, Mod etc.... How can I display the actual name ?
Where do you want this? A who's online legend would be the viewgroups plugin.
I just want to display the current logged in users usergroup on the index.
Where abouts? The welcome message, user link?
If it is a template add this code which should only show the group id.
{$user['usergroup']}
But thats my problem, I dont want to display ID. I want to display the group name.
You'll need to run a query or two probably. First you'll need to get their usergroup id and then run a query for usergroup table:

$uid = intval($mybb->user['uid']);
$getuser = get_user($uid);
$usergroup = $getuser['usergroup'];

//Now we get usergroup name

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

while($info = $db->fetch_array($query))
{
$usergroup_name = $info['title']; //This will be the usergroup title/name
}

$db->free_result($query);
^ Ouch. User groups are already in the cache.
Yeah, you could use that. Wink
(2012-12-03, 07:22 AM)Omar G. Wrote: [ -> ]^ Ouch. User groups are already in the cache.


And call it using... ?
$usergroups = $cache->read('usergroups');
$title = $usergroups[$mybb->user['usergroup']]['title'] // we use $mybb->user , current user

This is how you get the usergroup title from the cache.

Note that there is the display group too, you should be checking that as well, as MyBB does i in posts/profiles/etc IIRC.
Pages: 1 2