MyBB Community Forums

Full Version: Query to select a random user from group
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to pick a random member from the group with the id of 8, and I can't get the proper code. I keep getting Resource id #XXX returned. This is running inside of a plugin that I'm using.

Here's what I've come up with



//pick a random user from the group
$usergroupIn = '8';
$minPosts = '0';
$uid = $db->query("SELECT uid FROM ".TABLE_PREFIX."users WHERE usergroup = '$usergroupIn' AND postnum >=$minPosts  ORDER BY rand() LIMIT 1");
$username = $db->query("SELECT username FROM ".TABLE_PREFIX."users WHERE uid = '$uid' LIMIT 1");



Anyone have an idea what I'm doing wrong?
Try this;
//pick a random user from the group
$usergroupIn = '8';
$minPosts = '0';
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE usergroup = '$usergroupIn' AND postnum >=$minPosts  ORDER BY rand() LIMIT 1");
$user = $db->fetch_array($query);
$username = build_profile_link($user['username'], $user['uid']);
Thank you very much, that worked perfectly!