Issue: I have a field in mysql that is binary and I want to extract the various values
within it based upon their combined values.
1. There is an array of items that are coded to an integer.
2. To save space, instead of a mysql field for each, I am using a binary #.
3. Ex: 1 = Tech1, 2= Tech2, 4= Tech3, 8= Tech4 etc...
So.. Instead of having 20 or so fields for each record, I save them as a binary #
such that if the User has Tech1 and 2, Tech1 =1 add Tech2 = 2 == (1 + 2) 3
such that if the User has Tech2 and 3, Tech2 =2 amd Tech3 = 4 == (2 + 4) 6.
I want to write in php or java a function to extract the #s so when I do the printout,
instead of 3, it would print Tech1 and Tech2.
Examples of #s
1 = (1) = Tech1
2 = (2) = Tech2
3 = (1+2) = Tech1 and Tech2
4 = (4) = Tech3
5 = (4 + 1) = Tech3 and Tech1
6 = (4 + 2) = Tech3 and Tech2
7 = (4 + 2 + 1) = Tech3, Tech2, and Tech1
Mysql table has (2) fields:
-- Units (table)
ID - type binary 1,2,4,8, etc
Name - type varchar(30)
In the MainUsers table, I would store them as:
-- MainUsers (table)
ID - type binary
UID - type integer (index and autoincre) ID for the actual User
Name - type varchar(30) holds the name of the User.
Instead of having indiv. fields for each Unit.
The MainUsers would look like this
UID ID Name ... 1 1 User1 2 15 User2 3 12 User3 while the Units would look like this ID Name 1 Tech1 2 Tech2 4 Tech3 8 Tech4 16 Tech5 32 Tech6 54 Tech7 128 Tech8 256 Tech9 512 Tech10 ...
In the above,
User 1 would have Tech1
User 2 would have Techs 1-4
User 3 would have Techs 3-4
I can connect to the db and pull the fields into a php array. I can also update it to add a Tech
to the User (one they do not have yet) w/Update. But am lost from there.
Don't need to "select" what we want (ie do we want a paticular or not),
just print all the info. --- SELECT * from Units