MySql: storing multiple data in a database

I have a list of checkboxes in my form, the user can select any of them or only all of them.
Think that the user chooses a sport that interests him.

I need a better database structure to store this user. So in the future I will be able to get all this data.

I think I can just save each (userID, sport) choice as a new row in the database table. But this confuses me, because the table will expand faster just by a few users.

Any ideas, brothers?

+3
source share
2 answers

You can set up a many-to-many table, for example:

FavoriteSports
------
id user_id sport_id

1  5        20

Where do you have:

User
-------
id name

5  Mike

Sport
-----
id name

20 Football

, , .

+3

, , .

, .

- , .

userID    userName    sport

2

users
userID    userName    sportID

sports
sportID   sport

3

users
userID    sportName

sports
sportID   sportName

user_sports
userID    sportID

user_sports , , .

, , .

, , . , . , .

+3

All Articles