In this query in looking for comments, and if there are any comments it should be displayed, if there are’nt any comments it should display No comments yet.
The comments are displayed correctly but the if function to display that there arent any comments is not working.
$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>";
}
}
You should reorganize your code and you have a mistake in the compare for 0 comments: