你怎么能不向特定表中的用户显示行 [英] How could you do to not show rows to users that are in a specific table
问题描述
我正在创建一个网站,用户可以在其中发布链接并与之互动.
I'm creating a website where users can post links and interact with them.
向所有用户显示一个包含用户所有链接的表格.
All users are shown a table with all the links of the users.
但是我需要问一个问题,因为当用户与链接交互时,该链接将不会再次显示.即当用户点击一个链接时,该链接只对点击的用户消失
But I need to ask a question, for when a user interacts with a link, that link will not be shown again. That is, when a user clicks on a link, the link disappears only for the user who clicked
我做了以下事情.
我有存储所有用户的表(用户).
I have the table (users) where all the users are stored.
Table1 (users):
----------------
| id | username |
----------------
| 1 | user1 |
----------------
| 2 | user2 |
----------------
| 3 | user3 |
----------------
这是存储所有链接的第二个表
This is the second table where all the links are stored
Table2 (links):
----------------
| id | urls |
----------------
| 1 | url1 |
----------------
| 2 | url2 |
----------------
| 3 | url3 |
----------------
现在假设(表 1 的 USER2(用户))点击了以下链接(表 2 的 URL1 和 URL2(链接)).
Now suppose that (USER2 of table 1 (users)) clicked on the following links (URL1 and URL2 of table2 (links)).
当用户点击一个 url 时,以下值存储在第三个表中,如下所示:
When the user clicks on an url, the following values are stored in a third table as follows:
Table3 (blockuser):
-----------------------
| id | idLinks | users |
-----------------------
| 1 | 1 | user2 |
------------------------
| 2 | 2 | user2 |
-----------------------
现在我希望以下列方式向每个用户显示包含所有链接的表格.这就是我想要实现的目标:
Now I would like the table that contains all the links to be shown to each user in the following way. This is what I want to achieve:
User1: User2: User3:
-------------------- -------------------- --------------------
| TABLE: ALL LINKS | | TABLE: ALL LINKS | | TABLE: ALL LINKS |
-------------------- -------------------- --------------------
| ID | URLS | | ID | URLS | | ID | URLS |
-------------------- -------------------- --------------------
| 1 | url1 | | 3 | url3 | | 1 | url1 |
-------------------- -------------------- --------------------
| 2 | url2 | | 1 | url2 |
-------------------- --------------------
| 3 | url3 | | 1 | url3 |
-------------------- --------------------
这就是我能够实现的目标.
And this is what I have been able to achieve.
User1: User2: User3:
-------------------- -------------------- --------------------
| TABLE: ALL LINKS | | TABLE: ALL LINKS | | TABLE: ALL LINKS |
-------------------- -------------------- --------------------
| ID | URLS | | ID | URLS | | ID | URLS |
-------------------- -------------------- --------------------
| 3 | url3 | | 3 | url3 | | 3 | url3 |
-------------------- -------------------- --------------------
也就是说,当用户点击一个链接时,该链接不再向所有用户显示.
That is, when a user clicks on a link, the link is no longer displayed for all users.
但是我想要实现的是当用户点击一个链接时,该链接将停止显示,只对点击该链接的用户.....
But what I want to achieve is that when a user clicks on a link, the link will stop showing, only for the user who clicked on the link.....
这是我必须显示表格的代码:
This is the code I have to show the table:
SELECT
*
FROM
links
LEFT JOIN
blockuser ON blockuser.idLinks = links.id
WHERE
blockuser.idLinks IS NULL
推荐答案
我知道了.如果有人对未来感兴趣,这是正确的答案.
I have got it. This is the correct answer in case someone is interested in the future.
SELECT *
FROM links
WHERE id NOT IN
(SELECT idLinks FROM blockuser WHERE idUsers = 2)
或
SELECT *
FROM links
WHERE id NOT IN
(SELECT idLinks FROM blockuser WHERE users = 'user2')
这篇关于你怎么能不向特定表中的用户显示行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!