View Full Version : Why would this code not work...
dstruct2k
05-21-2004, 04:10 AM
$users = explode(" ",$event['users']);
foreach ($users AS $reggeduser) {
if ($reggeduser = $bbuserinfo['userid']) {
$registered = 1;
}
}
Why wouldn't this work?
$event['users'] is populated with a space-delimited field from the database, full of userids.
dstruct2k
05-21-2004, 04:45 AM
Nevermind, must be late... (12:45 AM :))
$users = explode(" ",$event['users']);
foreach ($users AS $index => $value) {
if ($value == $bbuserinfo['userid']) {
$registered = 1;
}
}
dstruct2k
05-26-2004, 05:05 PM
Similar idea now, but now I want to join "$users" with the `user` table to get the username of every registered user. :) Ideas?
I could do it where 1 query is executed for every userid registered, but that's very.... excessive. :)
dstruct2k
05-26-2004, 05:11 PM
How's this?
$userids = explode(" ",$event['users']);
foreach ($userids AS $index => $value) {
if ($firstdone = 0) {
$querystuff = "$value";
$firstdone = 1;
} else {
$querystuff .= "OR WHERE userid = $value";
}
}
$names = DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = $querystuff");
It's just kinda random thoughts put into code, but would it do what I want?
Xenon
05-27-2004, 12:31 PM
that's bad, and not working at all ;)
better way:
$userids = explode(' ', $event['users']);
// make sure to have at least one id
$userids[] = 0;
//now get users and their names:
$users = $DB_site->query("
SELECT userid, username
FROM " . TABLE_PREFIX . "user
WHERE userid IN (" . implode(', ', $userids) . ")
");
//and now loop through the event users.
while($user = $DB_site->fetch_array($users))
{
// do your stuff in here.
}
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.