简体   繁体   中英

MySQL database table relationships

I am having trouble understanding how I should structure my database tables. I want users to be able to upload a name (just the first name) of someone they know. The names they upload get stored in a table called people (with an auto-incrementing primary key). I then want, on a separate page, the names the user uploaded to be displayed. On this page, users can create a list. For example, 'white people'. Then I want users to be able to create another list(s) using the names from the list 'white people'. It could break down like this:

People> Matt, Adam, Alex, Aaron, David, Whites> Matt, Adam, Aaron, Friends> Matt, Adam, Enemies> Aaron,

I am absolutely perplexed as to how I should approach this. Can arrays be stored in a column in a database? Is that good practice/functional? How many tables am I going to need? Please any advice will help me. I am no beginner with PHP.

Storing array in table will not be good approach. Will be difficult to manage (update,fetch) and search data.

I think 2 tables are good:

1) people :

user_id | namw

2) lists :

id | user_id |joined_user_name | relation (friend/enemy)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM