![]() |
Multiple CheckBox
Hi,
I have Any Form For registering user. how to insert multiple rows in mysql for each user. my form : <input type = "text" name = "color" size = "10"><br> <input type = "checkbox" name = colors[] value = "red">Red <input type = "checkbox" name = colors[] value = "blue">Blue <input type = "checkbox" name = colors[] value = "green">Green <input type = "checkbox" name = colors[] value = "megenta">Megenta how to insert multiple rows in mysql for each user. MY mysql table is : |id|name|lastname|color|date|desc and how to show color list for each user . example : user 1 : red - blue user 2 : blue - green . . etc thanks. |
So you want to stored an array of selected colors in 1 field.
I would say store the array as a string in the field. Something like this: php Code:
Then when you want to show the list, just query the db and split by the ';' string and you would get back the array of colors. |
The only problem with storing serialized or imploded arrays in your database is that you complicate searching on those fields by a factor of ten. It goes up from there depending on the type of information being stored; in this case you could do a LIKE search and still get relatively accurate information, though in the process you eat your own performance.
mysql Code:
The beginnings of a user meta information table; you could easily switch to an NVP setup or simply create additional columns as necessary. Now with two simple queries you could easily pull up the information for a specific user, or all users who list the color blue, or combine both searches in one. Update your enum field to add more colors, or switch it for a varchar if the need becomes too great. |
| All times are GMT. The time now is 05:24 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0