doni
01-18-2005, 01:31 AM
I've got a form that has about 10 "select fields" which all allow multiple selections. I need to store the information provided via the form in MySQL.
I'm thinking that the "multiple" options could be stored as a BIT value if there is some sort of BITWISE operator available for use when I go to do a query.
Does anyone know if there is such an operator?
Thanks!
For those who don't know what I mean by a "Bit" value, I'll try and give a brief description.
The first item in the list is 1, then the second item is 2.
After that each item is DOUBLE the previous item.
If an option is not selected, then the option's value is set to ZERO. All the values are added up. No matter what you do, there is only ONE combination of selected items that will add up to any given number.
Option 1 = 1
Option 2 = 2
Option 3 = 4
Option 4 = 8
Option 5 = 16
Option 6 = 32
Option 7 = 64
Option 8 = 128
Total possible value = 255
This is where the terms "8 Bit", "16 Bit", "32 Bit" & "64 Bit" come from. Data is stored pieces.
If items one and two are selected and all other's are NOT selected, then the return value is 3.
Option 1 = 1
Option 2 = 2
Option 3 = 0
Option 4 = 0
Option 5 = 0
Option 6 = 0
Option 7 = 0
Option 8 = 0
Returns 3
If the items 3 and 5 are selected and all others are NOT, then the return value is 20.
Option 1 = 0
Option 2 = 0
Option 3 = 4
Option 4 = 0
Option 5 = 16
Option 6 = 0
Option 7 = 0
Option 8 = 0
Returns 20
Many programming languages include a function to decide which options are selected.
I'm thinking that the "multiple" options could be stored as a BIT value if there is some sort of BITWISE operator available for use when I go to do a query.
Does anyone know if there is such an operator?
Thanks!
For those who don't know what I mean by a "Bit" value, I'll try and give a brief description.
The first item in the list is 1, then the second item is 2.
After that each item is DOUBLE the previous item.
If an option is not selected, then the option's value is set to ZERO. All the values are added up. No matter what you do, there is only ONE combination of selected items that will add up to any given number.
Option 1 = 1
Option 2 = 2
Option 3 = 4
Option 4 = 8
Option 5 = 16
Option 6 = 32
Option 7 = 64
Option 8 = 128
Total possible value = 255
This is where the terms "8 Bit", "16 Bit", "32 Bit" & "64 Bit" come from. Data is stored pieces.
If items one and two are selected and all other's are NOT selected, then the return value is 3.
Option 1 = 1
Option 2 = 2
Option 3 = 0
Option 4 = 0
Option 5 = 0
Option 6 = 0
Option 7 = 0
Option 8 = 0
Returns 3
If the items 3 and 5 are selected and all others are NOT, then the return value is 20.
Option 1 = 0
Option 2 = 0
Option 3 = 4
Option 4 = 0
Option 5 = 16
Option 6 = 0
Option 7 = 0
Option 8 = 0
Returns 20
Many programming languages include a function to decide which options are selected.