Howdy,
I was wondering if anyone can help me with this. I'm trying to display how many people have commented on a news article on the index page. The view number of comments function works fine if the person clicks on that particular news page. It will show how many people have commented. But on the main index page it still shows 0 comments. That's because the number of comments is based on the news ID that gets passed on.
Is it possible to put query within query? Or is there another way to do it?
Here is my query for the view number of comments:
dbase connection here
$entry = $_GET['id'];
$result = mysql_query("SELECT COUNT(id) AS numcomments FROM news_comments WHERE entry ='$entry'") or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$numcomments = $row["numcomments"];
}
return $numcomments;
And here's the index page query:
include('viewcomments.php');
$numcomments = viewcomments();
dbase connection here
$query = "SELECT * FROM news_entries ORDER BY id";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$id = $row["id"];
$title = $row["title"];
$entry = $row["entry"];
print "$title";
print "$entry";
print "$numcomments";
}
note: the view number of comments function pulls up data from a different table and that the ID number did not get passed on. I know the solution might be something simple but my brain is dead at the moment.
Many thanks beforehand.