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
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/>";
}
?>

Link to comment
Share on other sites

when i run that in my script i get this

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #15' at line 1
Link to comment
Share on other sites

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/>";
}
?>

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.