如果我將if($comments_count == 0)
更改爲if($comments_count == 1)
,它會回顯文本(如果有1條評論)。但恢復到== 0
,該命令不會被執行。我嘗試在沒有評論的頁面上回顯$ comments_count的值,並且它說0。但是if-else忽略它並且不打印任何內容。如果語句在值爲零時不起作用(PHP)
這是代碼:
$query = "SELECT * FROM comments WHERE id = {$set_id}";
$all_comments_set = mysql_query($query);
$comments_count = mysql_num_rows($all_comments_set);
while($comment = mysql_fetch_array($all_comments_set)) {
if($comments_count == 0) {
echo $comments_count;
echo "<div class='comments'><p>There are no comments to show right now. Be the first to comment!</p></div>";
} else {
echo $comments_count;
echo "<div class='comments'>
<p class='commenter'><a href=''>".$comment['commentAuthor']."</a></p>
<p>".$comment['comment']."</p>
</div>";
}
}
如果你已經知道你沒有評論,你肯定不想迭代那個'while'循環嗎? –
確實如此,這是有道理的。 – catandmouse