我是所有数据库方面的新手。我想做的是保存属于用户的电影列表。例如,用户“james”喜欢以下电影“james bond, matrix, the revenant, batman”。我不知道如何将这个电影列表分配给用户“james”,我不知道如何为此创建我的表和字段。如果您能给我一个提示,我将不胜感激。
谢谢
最佳答案
用户表
id | user | other | email
电影表
id | name | year | etc
user_movie(这称为数据透视表)
user_id | movie_id
数据透视表相当惊人。 例子
users
id | name | details
3 | Hakim | xxxxxxx
4 | Mohammed | xxxxxxx
videos
id | name | year
2 | matrix | 2000
3 | Batman R.| 2008
4 | deadpool | 2016
5 | Minions | 2015
user_video (pivot table)
user_id | video_id
3 | 3
3 | 5
4 | 2
4 | 3
4 | 4
这样一个用户可以观看多个视频,反之亦然。 :)
关于mysql - 为用户分配电影列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36253983/