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

Source: Internet
Author: User
Tags php and mysql
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

  • Related Article

    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.