我一直在努力弄清楚如何"Hottest Posts"
选择帖子,most upvoted in shortest time
选择帖子。
我有2个数据库表:
fun_posts:
fun_post_upvotes:
我的最新代码仍然不起作用:
$stmt = $this->conn->prepare("SELECT * FROM fun_posts, (SELECT image_id, COUNT(*) FROM fun_post_upvotes GROUP BY image_id)
WHERE id = image_id ORDER BY id DESC, upvotes DESC");
答案 0 :(得分:1)
尝试使用此查询:
$stmt = $this->conn->prepare=("SELECT * , (SELECT COUNT(*)
FROM fun_post_upvotes
WHERE image_id=fun_posts.id
GROUP BY image_id)
FROM fun_posts
ORDER BY fun_posts,id DESC, fun_posts.upvotes DESC");