I have a database with hundreds of records (certainly it's not a huge database but I'd like to keep it that way). I want to let users create as many groups from the records as they wish (put any of the records into any of these groups). My idea was to use a binary number at each row, where bits would indicate whether the record is part of the corresponding (power of 2) group or not. Say there are 8 groups, therefore 8 bits:
banana | ... | 00010011 // banana is in group 0,1 and 4
orange | ... | 00010000 // orange is in group 4 only
flower | ... | 11111111 // flower is member of every group
This is very tiny and convenient, easy to handle in the WHERE clause - however, this cannot go on forever, eg to change the bits I'm using PHP's bindec()/decbin() functions which have limits in the maximum number of characters. I'd be grateful for any advice.
I would recommend a matrix of records and groups, a meta table.
One table with your records (1:banana, 2:orange, 3:flower etc.) One table with the user created groups (100:group1, 200:groupfruits, 300:groupplants, 400:groupwhatever).
One table that holds the connections between group and records:
group_id | record_id
100 | 1
100 | 3
200 | 1
200 | 2
300 | 3
400 | 1
400 | 2
400 | 3
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.