How do I save the check box to the database and read it from the database? with PHP and MySQL.
1 2 3
Reply content:
How do I save the check box to the database and read it from the database? with PHP and MySQL.
1 2 3
Method 1, using form form
Use the same name followed by the brackets, for example inlinecheckbox[]
Backend Get Inlinecheckbox Array
Method 2, customizing the POST request
With jquery, get all value, assemble it into a value, post back end, parse it yourself
Not very clear landlord want to express, first follow your own understanding answer it.
Suppose there is a problem "your hobby", multiple choice, choose Basketball, football, billiards three items, then the database may correspond to a field called hobby, the value of this field is the three answers, the three answers according to the provisions of the link linked, such as "basketball | football | billiards".
So at the time of reading, first use explode to disassemble the answer into an array, a loop array, a comparison of the answer, two values, the answer is selected, give the answer to the value of the HTML attribute checked, you can.
A more primitive simple and brutal multi-choice problem is solved.
Store multiple values in a column (JSON string or you can invent another code). Note that this is a violation of 1NF, but the disadvantages are limited.
Open another table with the foreign key
Open multiple column and save one value