sql - MySql adding too many records for one simple checkbox form? -
i have created form contains lot of checkboxes , i'm wondering how set in mysql database.
here illustration of form:
label: amount
checkboxes: little | many | not many | etc. etc.
label: basket type
checkboxes: wooden basket | steel basket | etc. | etc.
label: fruits
checkboxes: bananas | apples | oranges | etc. | etc.
in above illustration can pick multiple amounts illustration want basket little or many pieces fruit in them. can take 1 basket type, , can take 1 or multiple types of fruits.
all these seperate items have loaded database , id added checkbox.
the way im storing them when submitting form is: table: fruitbasket record 1: fruitbasket id = 1 fruit id = 1 basket type = 1 amount id = 1 record 2: fruitbasket id = 1 fruit id = 1 basket type = 1 amount id = 3
so submitting form 1 time lets 10 checkboxes selected generate lot of records. lot of users creating these , there alternative compare these fruitbaskets.
so question is, current way of storing info right because seems inefficient , generates many records. there way of storing info 1 fruit basket?
i suggest using bit-field store each fruit basket. straight compare fruit baskets using bitwise operators, etc. if utilize javascript constrain users options available, should work fine.
example:
// quantities little = 1 (0x0000000000000001) many = 2 (0x0000000000000010) not_so_many = 4 (0x0000000000000100) all_qtys = 7 (0x0000000000000111) // basket type wooden = 8 (0x0000000000001000) steel = 16 (0x0000000000010000) all_baskets = 24 (0x0000000000011000) // fruit types bananas = 32 (0x0000000000100000) apples = 64 (0x0000000001000000) all_fruit = 96 (0x0000000001100000) user_selection = little | steel | bananas | apples; (0x0000000001110001) other_user_selection = little | wooden | bananas | apples; (0x0000000001101001) // utilize bitwise , compare fruit types... if((user_selection & all_fruit) == (other_user_selection & all_fruit)) echo "fruit selection same!";
mysql sql checkbox many-to-many
No comments:
Post a Comment