It would be nice of the total number of comments left for each article were totaled and returned just beneath the news article.
My trouble is that all that is being totaled with the below code is the entire number of comments left for ALL news articles ever written.
Please can you make it only return the correct number of articles for that specific piece of news?
Thanks!
Code: Select all
$sql = "SELECT COUNT(*) FROM comments GROUP BY News";
$result2 = mysql_query($sql);
$num = mysql_result($result2, 0);
$result = mysql_query("SELECT * FROM news ORDER BY Date desc");
while($row = mysql_fetch_array($result))
{
echo "<div id=\"news-feed\"><div id=\"news-title\">" . $row['Title'] . "<br /></div>";
echo "<div id=\"news-date\">" . $row['Date'] . "<br /><br /></div>";
echo "<div id=\"news-story\">" . $row['Story'] . "<br /></div>";
echo ' <div id="comment-links">' . $num . ' comments' . '</div>';
if (isset($_SESSION['Id'])) {
echo ' <a href="comment.php?news-id=' . $row['Id'] . '" id="comment-links">Leave a comment </a> ';
}
echo "</div>";
}