php - mysql查询隐藏被阻止的用户所有帖子

标签 php mysql arrays laravel

表名称:user_post

id     user_id    post

1         2       hi ths is aaaaa

2         3       hi ths is yyyyyy

表名称:user_block

id      post_id     user_id  block_id  status

1      1                2       4         1

请告诉我被阻止的用户所有帖子中的选择查询都应该隐藏我的查询是:

SELECT * FROM `user_block`
  WHERE `id` NOT IN (
    SELECT `post_id` FROM `user_block`
      WHERE `user_id` = '{$userID}'
      AND `status` = '1'
  )

但是此查询不会隐藏被阻止的用户的所有帖子

最佳答案

这个:

select * from user_post
where '{$userID}' not in (
  select user_id from user_block
  where status = '1'
)

如果 user_blockuserid 的值为 1,则将隐藏所有帖子。
如果您希望用户只看到他自己的帖子:

select * from user_post
where '{$userID}' not in (
  select user_id from user_block
  where status = '1'
)
and user_id = '{$userID}'

关于php - mysql查询隐藏被阻止的用户所有帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55098921/

相关文章:

MySQL 数据库导入程序

mysql - 如何在执行 Union 时使用 Rand() 的 ORDER

ios - 不能分配给任何对象类型的不可变表达式

c# - 使用 Unity3d 连接到 MySQL 服务器?

php - 引用 - 这个错误在 PHP 中意味着什么?

arrays - 在 ruby​​ 数组中查找距离对

php - 如何修复对未定义函数 mysqli_connect() 的调用

javascript - 我无法使用 javascript 通过 ajax 将内容发布到 php

php - 删除用户和唯一电子邮件地址

javascript - 我通过 jquery 字符串发送跨站点伪造 token ,但在下一页上我生成一个新 token ,然后它们的 token 永远不会匹配