我目前正在使用PHP脚本来回显视频和投票,但是我无法正确获得MySQLi查询。
主表heat
包含视频,表heat_votes
包含投票。我想回显每个项目的投票数量以及用户是否投票。
我想出了以下代码,它可以工作,但只输出第一行。
$userid = $_GET['userid'];
$sql1 = " SELECT COUNT(votes.voteid) as votes_total, COUNT(userVotes.voteid) as voted_by_user, heatFeed.heatid, heatFeed.addedby, heatFeed.heat_title, heatFeed.heat_author, heatFeed.heat_thumb, heatFeed.heat_yt_code, heatFeed.heat_addedon, heatFeed.heat_boostscore
FROM heat as heatFeed
LEFT JOIN heat_votes as votes
ON heatFeed.heatid = votes.heat_id
LEFT JOIN heat_votes AS userVotes
ON heatFeed.heatid = userVotes.heat_id
AND userVotes.userid = '$userid'
WHERE heatFeed.heat_featured='1'
AND heatFeed.heat_active='1'";
$result1 = $connect->query($sql1);
我知道查询有些棘手,希望有人能够指出正确的方向。