我正试图通过upvote在我的页面上显示我的帖子。
我的表格帖子:
(id, post_name, post_description, post_category, post_subcategory)
和表投票:
(id, post_id, vote_rank)
我可以用
显示我的所有帖子$bdd->query('SELECT * FROM posts WHERE post_subcategory = "'.$_GET['s'].'" ORDER BY post_name');
我尝试了JOIN但没有出现。
$bdd->query('SELECT *
FROM posts AS p
JOIN votes as v ON v.post_id = p.id
WHERE p.post_subcategory = "'.$_GET['s'].'"
ORDER BY v.vote_rank');
有什么想法吗?
答案 0 :(得分:1)
$bdd->query('SELECT p.*
FROM posts p LEFT JOIN votes v ON v.post_id = p.id
WHERE p.post_subcategory = "'.$_GET['c'].'"
ORDER BY v.vote_rank');
试一试
答案 1 :(得分:0)
尝试使用内连接
$bdd->query('SELECT p.*
FROM posts p inner join votes v on v.post_id = p.id
where p.post_subcategory = "'.$_GET['c'].'"
order by v.vote_rank');