Get number of posts in a topic PHP
Posted
by Wayne
on Stack Overflow
See other posts from Stack Overflow
or by Wayne
Published on 2010-06-15T20:41:41Z
Indexed on
2010/06/15
20:42 UTC
Read the original article
Hit count: 294
How do I get to display the number of posts on a topic like a forum. I used this... (how very noobish):
function numberofposts($n)
{
$sql = "SELECT * FROM posts
WHERE topic_id = '" . $n . "'";
$result = mysql_query($sql) or die(mysql_error());
$count = mysql_num_rows($result);
echo number_format($count);
}
The while loop of listing topics:
<div class="topics">
<div class="topic-name">
<p><?php echo $row['topic_title']; ?></p>
</div>
<div class="topic-posts">
<p><?php echo numberofposts($row['topic_id']); ?></p>
</div>
</div>
Although it is a bad method of doing this... All I need is to know what would be the best method, don't just point me out to a website, do it here, because I'm trying to learn much. Okay? :D
Thanks.
© Stack Overflow or respective owner