Smackie Posted July 28, 2007 Share Posted July 28, 2007 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 More sharing options...
Barand Posted July 28, 2007 Share Posted July 28, 2007 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 https://forums.phpfreaks.com/topic/62238-forum-topic-count-help/#findComment-309801 Share on other sites More sharing options...
Smackie Posted July 29, 2007 Author Share Posted July 29, 2007 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 https://forums.phpfreaks.com/topic/62238-forum-topic-count-help/#findComment-309832 Share on other sites More sharing options...
Barand Posted July 29, 2007 Share Posted July 29, 2007 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 https://forums.phpfreaks.com/topic/62238-forum-topic-count-help/#findComment-309957 Share on other sites More sharing options...
Smackie Posted July 30, 2007 Author Share Posted July 30, 2007 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 https://forums.phpfreaks.com/topic/62238-forum-topic-count-help/#findComment-311054 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.