MyBB Community Forums

Full Version: Grab All Users in a field
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Basically some fields in the database I notice separate User IDs with a comma. I was wondering how I can make it grab all the User IDs in that so I can do whatever I want to do with them?

For example the buddy list uses a comma to separate out users.
You can grab them with explode() function, like this;
$uids = array(1,2,3,4,5);
$each_uid = explode(",",$uids);
Thanks, that worked perfectly. One more question, is there a way to select only users from the database in an array? I found a work around, but it takes an extra query for each person and if a list gets long, that can have an impact on performance.

I'd like to have it select each uid on the list. Something like this:
$db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE uid in_array");
It's the last part I'm not sure about.
You can do something like this:
$buddylist = "1,2,3,4"; // normally from the database
$query = $db->simple_query("users", "*", "uid IN(".$buddylist.")");
while($user = $db->fetch_array($query))
{
    print $user['username'];
}

In case you don't use the mysql database abstraction, here is the plain SQL:
SELECT * FROM table WHERE id IN(1,2,3,4)
Other than it being uid instead of id, it works. Thanks.
(2011-04-07, 01:31 PM)dragonexpert Wrote: [ -> ]Other than it being uid instead of id, it works. Thanks.

Oops, my bad. Sorry. Edited in my previous post.