简体   繁体   English

如何在MySQL表行中存储多个用户

[英]How to store multiple users in a MySQL table row

What I have is a program that allows users to monitor posts by specifying what they are looking for. 我拥有的是一个程序,该程序允许用户通过指定所需内容来监视帖子。 I'm predicting that many users will monitor the same posts, and would like to instead of having them all listed as separate posts, have all of the users grouped into the same row. 我预计许多用户将监视相同的帖子,并且希望将所有用户分组到同一行中,而不是将它们全部列为单独的帖子。

I'm unsure of wether MySQL has a way to point to multiple users in a different table, or some other way of doing it. 我不确定MySQL是否有一种方法可以指向不同表中的多个用户,或者采用其他某种方式。 I've seen things such as joining mentioned, but have not seen any ways to implement it in the way that I would like. 我看过提到的诸如join之类的东西,但是没有看到任何以我想要的方式实现它的方法。

What i'm wondering if it's possible to do: 我想知道是否有可能做到:

Table 1:                                        Table 2:

Platform   Post Name          Users             Users
-----------------------------------             ----------------
PC         Title              [   ] ----------> Jane
                                          |---> Bob 
                                          |---> Roger

Is it possible to do this, or what way should I be going about this? 有可能这样做吗,或者我应该怎么做呢?

Putting user names in a comma-separated list is a terrible solution. 将用户名放在逗号分隔的列表中是一个糟糕的解决方案。 Please don't do that. 请不要那样做。 It leads to all sorts of problems. 这会导致各种各样的问题。

The best way to do this is to create a new table with two columns: USER_ID and POST_ID . 最好的方法是用两列创建一个新表: USER_IDPOST_ID Whenever a user wants to monitor a post, add a row with the user's ID and the post's ID. 每当用户想要监视帖子时,请添加带有用户ID和帖子ID的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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