PDA

View Full Version : Decoding Bitfield for Custom Use


Muppettt
07-30-2007, 12:15 PM
Hey,

I'm currently making a custom usercp (outwith vB but including certain parts/files into it). I'm trying to reproduce the options page and notice vB stores all the option data into a bitfield.

How can i 'decode' the bitfield to show what options a user currently has set? I know i can select the data using

SELECT username, email FROM user WHERE options & 16

so that would display everyone with adminemail set to ON, but how would i make it so that it pulls the options bitfield and 'decode' that to show what features the user currently has ON (as in text outputs - 16 = Receive Admin Emails). I assume there would be an array somewhere with all the pertinent data?

And i assume for UPDATING the user table with the a new adminemail option (if changed) it would be:

UPDATE user SET options = options - 16 WHERE (options & 16) AND userid = 123

Muppettt
08-01-2007, 03:29 PM
Anyone?

Marco van Herwaarden
08-01-2007, 03:57 PM
You can find most bitfield values in Updating Options En Masse with Queries (http://www.vbulletin.com/forum/showthread.php?t=213135)

-=Sniper=-
08-01-2007, 06:01 PM
excellent :) thanks that might come in use.

Marco van Herwaarden
08-01-2007, 07:11 PM
It has been there for a very long time. ;)