Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySql: Store multiple choice data in database

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.

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.

Any ideas, brothers?

like image 524
Almas Adilbek Avatar asked Apr 19 '26 03:04

Almas Adilbek


1 Answers

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

FavoriteSports
------
id user_id sport_id

1  5        20

Where you have:

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.

like image 160
Mike Lewis Avatar answered Apr 20 '26 17:04

Mike Lewis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!