MyBB Community Forums

Full Version: Get usergroup by id
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi!
How to get usergroup by id?
<?php

define('IN_MYBB', 1);
define('THIS_SCRIPT', basename(__FILE__));
require_once './global.php';

// Read usergroup cache
$usergroupcache = $cache->read('usergroups');

// Usergroup array
$groups = array('4','3');

foreach($groups AS $validgroup)
{
	print($usergroupcache[ $validgroup ]['title'].'<br />');
}

Image:

[Image: mfpjjt.png]
They're in ACP : 1 - 7
No, it's about php code for developement plugin.
(2016-07-27, 10:07 AM)adi19 Wrote: [ -> ]No, it's about php code for developement plugin.

My code will print the usergroups name specified in the $groups array.
My bad! Not get usergroup by id group.
Get usergroup by id user (uid).
I have a array with uid and I want usergroup id by uid.
(2016-07-27, 10:15 AM)adi19 Wrote: [ -> ]My bad! Not get usergroup by id group.
Get usergroup by id user (uid).
I have a array with uid and I want usergroup id by uid.

Ah. You can use this!

<?php

define('IN_MYBB', 1);
define('THIS_SCRIPT', basename(__FILE__));
require_once './global.php';

$uids = array('1','2','3','330'); // UID Array

foreach($uids AS $uid)
{
	$getinfo = get_user($uid);
	$group = $getinfo['usergroup'];
	print($group.'<br />');
}
Hmm...yes, but I want a good complexity.
For good complexity, it's about query, but i dont know what is the query.
The query is:
SELECT usergroup FROM mybb_users WHERE uid = variable_uid

with mybb code:
$result = $db->simple_select("users", "usergroup", "uid = {$uid}");
if($db->num_rows > 0) {
    $result = $db->fetch_array($result);
    $usergroup = $result['usergroup'];
}
Don't forget display_group and additional_groups!