简体   繁体   English

如何插入,将多个复选框更新为mysql?

[英]How To Insert , Update multiple checkboxes to mysql?

I have a form with 80 checkboxes.. Its a options form for car.. For example 我有一个带有80个复选框的表格。它是汽车的选项表格。例如

Colour: black , red , white , yellow etc.. How should i design my database for many options? 颜色: black , red , white , yellow等。我应该如何为许多选项设计数据库?

should i create 80 column in table? 我应该在表格中创建80列吗? or use implode() and save in a one column or multiple rows? 还是使用implode()并保存在一列或多行中? but when i need i should update it... 但是当我需要的时候我应该更新它...

Car_id |  black | red | white | yellow  |..... | option80 |
1            true     true     

how should i do ? 我应该怎么做 ? Thank you for your help 谢谢您的帮助

Check out normalization. 检查归一化。 That might help. 这可能会有所帮助。

Anyway, to help you get on your way, here's a basic setup for that. 无论如何,为了帮助您上路,这是一个基本设置。

+-----TABLE CAR------+
ID
NAME

+-----TABLE COLOR------+
ID
COLOR

+-----TABLE CAR_COLOR------+
CAR_ID
COLOR_ID

This makes sure you have a link table between CAR and COLOR 这可以确保您在CAR和COLOR之间有一个链接表

Hope this was helpful 希望这会有所帮助

If you plan to do in the future selection of the item by color, then it is better to create related tables: 如果您打算将来通过颜色选择项目,则最好创建相关表:

table of cars (car_id, car_name)

table of colors (color_id, color_name)

table of relation colors and cars (car_id, color_id)

(sql - join)

And if you plan to just use as a characteristic of the car, then one cell with all the flowers separated "|" 而且,如果您打算仅将其用作汽车的特征,则所有花都分隔为“ |”的一个单元格 and when you create insert in the database use implode(), and select from the database explode() 当您在数据库中创建插入时,请使用implode(),然后从数据库中选择explode()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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