Hi,
I'm trying to put together a block that shows "forum statistics" like the ones that typically come with phpbb forums and so on. You know, things like "currently active users", "number of threads", "number of posts".
Now, I think I have most of them down now - using a few snippets here and there - but I'm still missing a way to display the complete number of posts in the forums. The trouble is that replies are in reality comments, and how do you count the comments that are restricted to the forums? This is a small feature, I admit, but I'm weird that way ;)
Please correct me, if I'm way off - this is my first site with Drupal (ammenet.dk).
Anyone know, how to accomplish this or just point me in the right direction?
(I tried the drupal.org forums, but haven't gotten any replies yet, so I thought I'd try here)
thanks! Morten
Can't tell for sure because I don't have test data to play with but I think this will give you a count of all the node types that are forum and then add a count of all the comments ... That way you get an accurate count even if the original post doesn't have any comments.
SELECT count(*) FROM node n LEFT JOIN comments c ON n.nid=c.nid WHERE n.type='forum'
On 4/12/07, Morten Holmstrup morten@holmstrups.dk wrote:
Hi,
I'm trying to put together a block that shows "forum statistics" like the ones that typically come with phpbb forums and so on. You know, things like "currently active users", "number of threads", "number of posts".
Now, I think I have most of them down now - using a few snippets here and there - but I'm still missing a way to display the complete number of posts in the forums. The trouble is that replies are in reality comments, and how do you count the comments that are restricted to the forums? This is a small feature, I admit, but I'm weird that way ;)
Please correct me, if I'm way off - this is my first site with Drupal (ammenet.dk).
Anyone know, how to accomplish this or just point me in the right direction?
(I tried the drupal.org forums, but haven't gotten any replies yet, so I thought I'd try here)
thanks! Morten
-- [ Drupal support list | http://lists.drupal.org/ ]
Morten Holmstrup <morten <at> holmstrups.dk> writes:
The trouble is that replies are in reality
comments, and how do you count the comments that are restricted to the forums? This is a small feature, I admit, but I'm weird that way ;)
Please correct me, if I'm way off - this is my first site with Drupal (ammenet.dk).
Anyone know, how to accomplish this or just point me in the right direction?
I've got a similar thing set up on our site, but up until recently we only had comments on the forums, so there was no need to distinguish. If you've not got forum posts displaying it may help though, and if you find out how to do it let me know! This is straight from our php block (which is cached using blockcache so it doesn't run every page request).
<?php
$userTotal = db_fetch_array(db_query("select count(distinct(uid)) from users"));
foreach ($userTotal as $index => $valueu) { echo $valueu . " users,\n"; }
$postTotal = db_fetch_array(db_query("select count(distinct(nid)) from node where type = 'forum';"));
foreach ($postTotal as $index => $value) { echo $value . " topics and\n"; }
$commentTotal = db_fetch_array(db_query("select count(distinct(cid)) from comments"));
foreach ($commentTotal as $index => $valuec) { echo $valuec . " replies so far.\n"; }
?>