【发布时间】:2016-11-09 13:45:46
【问题描述】:
我需要一个 SQL 查询,它给出一个表的内容和第二个表的计数。我试过了,不行。
我有一个“cmets”表。而在另一个名为“likes”的表中,有 cmets 的点赞数。
在我的算法中,在“likes”表中,有一列名为“likeType”,如果是“1”表示点赞,否则(如果是“0”)表示不喜欢。我需要在一个查询中从“comments”表中带来评论,从“likings”表中获取likeType=1 和likeType=0 的计数。
这是我最好的尝试,但没有奏效:
PHP端:
$getFirst8Comments = "SELECT
episodecomments.cmtID,
episodecomments.cmtConEpisode,
episodecomments.cmtOwner,
episodecomments.cmtDate,
episodecomments.cmtContent,
episodecomments.cmtSpoiler,
SUM(IF(episodecommentsliking.liType='1', 1, 0)) AS likes,
SUM(IF(episodecommentsliking.liType='0', 1, 0)) AS dislikes
FROM episodecomments
LEFT JOIN episodecommentsliking
ON episodecomments.cmtID = episodecommentsliking.liCmtID
GROUP BY
episodecomments.cmtID,
episodecomments.cmtConEpisode,
episodecomments.cmtOwner,
episodecomments.cmtDate,
episodecomments.cmtContent,
episodecomments.cmtSpoiler
WHERE episodecomments.cmtConEpisode='$epID'
ORDER BY episodecomments.cmtID
DESC LIMIT 8";
while ($getF8C = mysqli_fetch_array($getFirst8Comments))
{
echo "Something coming through-<br>";
}
错误弹出:Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given in J:\file.php on line 3484 (error in variable $getFirst8Comments)
提前致谢。
【问题讨论】:
-
向我们展示您的查询尝试。
-
抱歉,已更新。我是新来的。 @jarih
-
这样更好。看?现在你的问题不再被否决了;-)
-
是的,看起来是这样,但你可以谦虚一点,这不会伤害任何人:)