if($comments_count == 0)
을 if($comments_count == 1)
으로 변경하면 텍스트가 1 개있는 경우 해당 텍스트가 반복됩니다. 그러나 == 0
으로 되돌아 가면 명령이 실행되지 않습니다. 코멘트가없는 페이지에서 $ comments_count의 값을 반향 출력하려고 시도했지만 0으로 표시됩니다.하지만 if-else는이를 무시하고 아무 것도 출력하지 않습니다.값이 0 일 때 if 문이 작동하지 않는 경우 (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