首页 > 解决方案 > mysql查询隐藏被阻止的用户所有帖子

问题描述

表名: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'
  )

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

标签: phpmysqlarrayslaravel

解决方案


这个:

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

如果里面userid有值,将隐藏所有帖子。 如果您希望用户只看到他自己的帖子:1user_block

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

推荐阅读