How do I save the check box to the database and read it from the database? Use php and mysql. How do I save the {code...} check box to the database and read it from the database? Use php and mysql.
1 2 3
Reply content:
How do I save the check box to the database and read it from the database? Use php and mysql.
1 2 3
Method 1: Use Form
Use the same name followed by brackets, such as inlineCheckbox []
The backend obtains inlineCheckbox as an array.
Method 2: Customize post requests
Use jQuery to obtain all values and assemble them into a value. post the backend and parse it by yourself.
If you are not quite clear about what the landlord wants to express, please answer it as you understand.
Suppose there is a question: "Your hobbies". If you select multiple options and choose basketball, football, and billiards, the database may correspond to a field named holobby, the value of this field is the three answers, which are linked according to the specified link character, such as "basketball | football | billiards ".
When reading, we first use explode to split the answer into an array, loop array, and compare the answer with one item. The two values are the same, indicating that this answer is selected, assign the html attribute checked to this answer.
A simple and rough multi-choice problem is solved.
Store multiple values in a column (json string or you can create another encoding). Note that this is against 1NF, but the disadvantage is limited.
Open another table with a foreign key
Open multiple columns and store one value each.