I'm having problems trying to query the total number of topics in each of my forums.
Basically, I am getting the same number for each forum. I only have 2 forums in the database. For testing purposes, I have 1 topic in one and 0 in the other but I am getting 1 for each forum.
Here is my query:
$query_topics = "SELECT topic_id, count(*) FROM topics JOIN forums ON (topics.topic_forum = forums.forum_id) GROUP BY topic_id";
$topics = mysql_query ($query_topics) OR die ('Cannot execute the query.');
$row_topics = mysql_fetch_assoc ($topics);
$total_topics = mysql_num_rows ($topics);
Here is my PHP for the table:
<table width="725" border="0" cellspacing="1" cellpadding="6" bgcolor="#CCCCCC">
<tr bgcolor="#E5E5E5">
<td width="525"><strong>Forum</strong></td>
<td width="100"><div align="center"><strong>Topics</strong></div></td>
<td width="100"><div align="center"><strong>Posts</strong></div></td>
</tr>
<?php do { ?>
<tr bgcolor="#FFFFFF">
<td width="525"><a href="view_forum.php?forum_id=<?php echo $row_forums['forum_id']; ?>"><?php echo $row_forums['forum_name']; ?></a></td>
<td width="100"><div align="center"><?php echo $total_topics ?></div></td>
<td width="100"><div align="center"></div></td>
</tr>
<?php } while ($row_forums = mysql_fetch_assoc ($forums)); ?>
</table>
Any help is appreciated. Many thanks!