php - 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'
)
但是此查询不会隐藏被阻止的用户所有帖子
解决方案
这个:
select * from user_post
where '{$userID}' not in (
select user_id from user_block
where status = '1'
)
如果里面userid
有值,将隐藏所有帖子。
如果您希望用户只看到他自己的帖子:1
user_block
select * from user_post
where '{$userID}' not in (
select user_id from user_block
where status = '1'
)
and user_id = '{$userID}'
推荐阅读
- logstash - 运行多个实例时无法启动 logstash - path.data 设置
- excel - Excel - 查找范围内有多少个单元格
- python - 无法解析从套接字接收的python中的Ctype结构
- mysql - 存储函数返回 NULL Mysql
- python-3.x - Python数据框在同一列中获取所有排列
- php - 如何将数组键和值附加到 html 元素?
- regex - 如何重新格式化 RFC5424 日志尾部的输出以更易于阅读?
- python - 更改不可调用模块的回溯
- c# - 为什么控制台应用默认使用代理?
- java - 为什么 getAnnotatedParameterTypes 看不到数组类型的注释?