PDA

View Full Version : quick question - query WHERE based on bitfield


Antivirus
04-06-2007, 07:27 PM
I looked long and hard before posting and tried to figure out myself, but...

I have a query which works fine as follows:

$dbusers = $db->query_read("
SELECT username, userid FROM " . TABLE_PREFIX . "user
WHERE usergroupid IN (" . $vbulletin->options['et_usergroupids'] . "," . $vbulletin->options['st_usergroupids'] . ")
ORDER BY username"
);


...but I need to change the WHERE clause to grab users who have a YES value for one of the bitfields instead of the $vbulletin->options['et_usergroupids'], etc...

I am trying to do the query as follows, but having problems:
incorrect code removed


Nevermind - figured it out, i forgot to define usergroup column (doh!)... for anyone who wants to know- following works:


$bit = $vbulletin->bf_ugp['scstpermissions']['canjoin_et'];
$dbusers = $db->query_read("
SELECT user.username, user.userid, usergroup.scstpermissions
FROM user
LEFT JOIN usergroup ON user.usergroupid = usergroup.usergroupid
WHERE ($bit & usergroup.scstpermissions)
ORDER BY username"
);