php - MySQL DB multiple data for field -


maybe have never searched in right place wonder best practice store multiple data in 1 field , have never found answer use.

let me more clear example.

let's have "hobbys" field in user_table

when user signup want add tennis, video game, , piano profile.

is better:

  1. to create different fields every hobby like: hobby_id_1, hobby_id_2, hobby_id_3

  2. or create single field called hobbys , insert data separated comma ? hobbys_id => 1,4,5 (is solution possible ?)

and when want update data , add new hobby example, how ?

any small appreciated.

thank in advance :)

this falls under many many relationship.

for storing many-to-many relationships, intermediate table stores primary keys (ids) of each relationship required. in case,

users_table(user_id,firstname,...)

hobbies_table(hobby_id,name,...)

users_hobbies_table(id,user_id,hobby_id)

here more elaborate explanation.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -