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:
<?php
$sql = "SELECT * FROM topics ORDER BY topic_id ASC LIMIT $start, $limit";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
?>
<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>
<?php
}
?>
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.
EDIT:
SQL:
Posts table:
CREATE TABLE `posts` (
`post_id` mediumint(8) NOT NULL AUTO_INCREMENT,
`topic_id` mediumint(8) NOT NULL,
`forum_id` mediumint(8) NOT NULL,
`user_id` mediumint(8) NOT NULL,
`post_time` varchar(100) NOT NULL,
`post_timestamp` mediumint(20) NOT NULL,
`post_ip` varchar(20) NOT NULL,
`post_reported` tinyint(1) NOT NULL,
`post_reportdesc` text NOT NULL,
PRIMARY KEY (`post_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
--
-- Dumping data for table `posts`
--
INSERT INTO `posts` VALUES(1, 1, 0, 1, '15th Junenee', 0, '', 0, '');
Topics table:
CREATE TABLE `topics` (
`topic_id` mediumint(8) NOT NULL AUTO_INCREMENT,
`section_name` varchar(25) NOT NULL,
`topic_title` varchar(120) NOT NULL,
`topic_description` char(120) NOT NULL,
`user_id` mediumint(8) NOT NULL,
`topic_time` varchar(100) NOT NULL,
`topic_views` varchar(1000) NOT NULL,
`topic_up` mediumint(11) NOT NULL,
`topic_down` mediumint(11) NOT NULL,
`topic_status` tinyint(1) NOT NULL,
PRIMARY KEY (`topic_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
This should help you understand a bit more.