Jump to content

Forum topic count help


Smackie

Recommended Posts

I created a forum and I am having problem with the counting of each topic and replies..

 

currently they count all the topics and posts i need it to only count the different id's like right now I got to posts on there with 5 topics they are both saying 5 topics in each there should be 2 in forumid 1 and 3 in forumid 2

 

here is the script that counts the forumid

 

$query = mysql_query("SELECT forumid FROM forum_question"); 
$topics = mysql_num_rows($query);

 

 

can someone help me please

Thank you

Smackie

Link to comment
https://forums.phpfreaks.com/topic/62238-forum-topic-count-help/
Share on other sites

try

<?php

$query = mysql_query("SELECT forumid, COUNT(*) 
        FROM forum_question 
        GROUP BY forumid");
$res = mysql_query($query) or die (mysql_error()."<p>$sql</p>");
while (list($id, $count) = mysql_fetch_row($res))
{
    echo "Forum $id : $count topics <br/>";
}
?>

Sorry

 

<?php

$query = "SELECT forumid, COUNT(*) 
        FROM forum_question 
        GROUP BY forumid";
$res = mysql_query($query) or die (mysql_error()."<p>$sql</p>");
while (list($id, $count) = mysql_fetch_row($res))
{
    echo "Forum $id : $count topics <br/>";
}
?>

i redid the scripts and came up with alittle more workable was looking at a friends count script he had for his forum which didnt work well for me but here is what i got so far

 

<?php 
$id = $_GET['id'];

$sql = mysql_query("SELECT * FROM header ORDER BY `id`");
while($rows = mysql_fetch_array($sql)){
$id = $rows['id'];
$a_id = $rows['id'];

$datetime = date('D dS M Y, h:i a', strtotime($rows['datetime']));

$get_num_topics = "select count(forumid) from forum_question where id = $id";
$get_num_topics_res = mysql_query($get_num_topics) or die(mysql_error());
$topics = mysql_result($get_num_topics_res,0,'count(forumid)'); 

$get_num_posts = "select count(question_id) from forum_answer where a_id = $a_id";
$get_num_posts_res = mysql_query($get_num_posts) or die(mysql_error());
$posts = mysql_result($get_num_posts_res,0,'count(question_id)'); 
?>
		  <tr>
    <td width="80%"><a href="../index.php?pages=topic&id=<?php echo $rows['id']; ?>"><?php echo $rows['heading']; ?></a><BR>     <?php echo $rows['description']; ?></td>
    <td width="10%" align="center"><?php echo $topics; ?></td>
    <td width="10%" align="center"><?php echo $posts; ?></td>
  </tr>

 

i need the it to count each topic and each posts in each category..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.