How to Store Multiple Options selected by User in a Table

前端 未结 3 1749
感动是毒
感动是毒 2021-01-23 14:50

So I want my users to be able to restrict who may contact them.

There are several factors they should be able to filter, including Age (e.g. Must be between 18 - 29), in

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-23 15:24

    No, don't store the values in CSV format in the database. Instead create a join table called user_drug and store one row for each user/drug combination:

    user
    id    name  income
    1     Foo   10000
    2     Bar   20000
    3     Baz   30000
    
    drug
    id    name
    1     Marijuana
    2     Cocaine
    3     Heroin
    
    user_drug
    user_id drug_id
    1       1
    1       2
    2       1       
    2       3
    3       3
    

提交回复
热议问题