MySql:在数据库中存储多项选择数据 [英] MySql: Store multiple choice data in database

查看:1910
本文介绍了MySql:在数据库中存储多项选择数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单中有一个复选框列表,用户可以选择其中的任何一个或全部。

考虑用户选择他感兴趣的运动类型。

I have a list of checkboxes in my form, user may chose any of them, or just all of them.
Think that user selects the type of sport he is interested.

我需要最好的数据库结构来存储这个用户选择。所以,以后,我可以得到所有这些数据。

I need the best database structure to store this user choise. So that, in future I can get all this data.

我想,我只是可以存储每个(userID,sport)choise作为数据库表中的新行。

I think, I just can store each (userID, sport) choise as a new row in database table. But it is confusing me, because table will expand faster with just a few number of users.

任何想法,兄弟?

推荐答案

您可以设置多对多表格,例如:

You can setup a many-to-many table such as:

FavoriteSports
------
id user_id sport_id

1  5        20

您有:

User
-------
id name

5  Mike

Sport
-----
id name

20 Football

这是有道理的,因为用户有很多运动,运动有很多用户。

This makes sense because a user has many sports, and a sport has many users.

这篇关于MySql:在数据库中存储多项选择数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆