简体   繁体   中英

Saving more than one tickbox to one DB column

I have a bunch of tick boxes that need to be inserted into one database column on submit, but I have no idea on how to accomplish this, I was thinking maybe jQuery or Javascript, any ideas?

Here is a snippit of code:

<input type="checkbox" name="vehicle" value="Bike" />
<input type="checkbox" name="vehicle" value="Car" /> 

so basically, when thy click on a heckbox, the value of te chckboxes that are checked should be put in a comma delimited string or alike, so that I can easily save it to one database column instead of many.

Thanx in advance!

You'll have to encode the state of the check boxes into the column in some way on the server side. For convenient visual confirmation you could use a string of ones and zeros to indicate checked/unchecked states. Or you could use an integer type whose bit values indicate the checked state if storage space is more important. Note that both of these strategies will require you to keep careful track of the order in which the values are stored, so adding/removing values to store in the column will be tricky.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM