在这个查询中寻找评论,如果有评论应该显示,如果没有评论应该显示No comments。
评论显示正确,但显示没有任何评论的 if 函数不起作用。
$comments = mysql_query ("SELECT * FROM comments WHERE post_id = '". $_GET['id']."'");
while ($comment = mysql_fetch_array ($comments)) {
//If there are'nt any results
if(mysql_num_rows($comment) < 0 ) {
echo "No comments yet!";
} else {
//If there are any results
echo "<p>" . $comment['comment'] . "</p>
<p><b>" . $comment['author'] . "</b>, " . date("M j, Y ", strtotime($comment["date"])) . "</p>";
}
}