![]() |
Multiple-Selection Checkbox Decoding
Yesterday, I needed to decode a Multiple-Selection Checkbox from vBulletin's custom profile for an external script. I'm not really that experienced at programming, but I through this together and it has worked for me quite well.
I figured most people wouldn't be all that interested in dealing with "binary stuff". I know I wasn't. PHP Code:
|
Can you give an example value of $vbulletin->userinfo['field1'] and an example output? :p
|
Sure
$vbulletin->userinfo['field11'] value would be = 1058 The output (if I print the array) would be with my example categories/values: Array ( [0] => Society [1] => Government [2] => Business ) ---- $vbulletin->userinfo['field11'] value would be = 1 The output (if I print the array) would be with my example categories/values: Array ( [0] => Art ) Brandon |
Hmm isn't this stored as a bitfield?
So: 1 = Society 2 = Government 4!! = Business 8 = Next option etc.. For example a value of 9 would mean that both "Society" (1) and "Next option" (8) is selected. Use bitwise operators to see if an option is selected. To test if "Government" (2) is selected: PHP Code:
|
What's a bitfield?
I guess I'll have to add that to me "to do" list. The method I used seams to work for what I'm doing, but I can almost guarantee there is a better way. I couldn't find anything by searching on vBulletin.org or in Google, so maybe this is a start. I'm sure it's a fairly rare situation anyway. Brandon |
Bitfields are used all across vBulletin, and they're pretty useful. As Marco has demonstrated, each successful "bit" is double the previous. There is a maximum of bits, of course, but that is something like 2^32.
|
Just to be clear - the maximum number of bits is normally 32, the value of the 32nd bit would be 2^31.
|
All times are GMT. The time now is 09:36 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|