How do I save the check box to the database and read it from the database?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.