【发布时间】:2015-06-17 20:28:14
【问题描述】:
在这种情况下我有
帖子表:
id
title
description
post_votes 表:
id
post_id
user_id
cmets 表:
id
post_id
user_id
content
用户表:
id
username
我有一个关于我的索引页(登录用户)的查询
select
`posts`.`id`,
`posts`.`title`,
`posts`.`description`,
COUNT(distinct post_votes.id) AS votes,
COUNT(distinct comments.id) AS comments
from `posts`
left join `post_votes` on `post_votes`.`post_id` = `posts`.`id`
left join `comments` on `comments`.`post_id` = `posts`.`id`
group by `posts`.`id`
这会显示所有帖子(事件)。对于每一个显示总票数和 cmets 的数量。此外,在索引页面上为每个帖子显示一个投票按钮。
用户可以对文章进行投票,我希望能够检查用户是否已经对每个帖子进行了投票,在这种情况下,显示禁用了该帖子的投票按钮。
我有用户 ID。
我该怎么做?
【问题讨论】: