PDA

View Full Version : Total Views For Forum


SystemLogic
03-07-2001, 03:24 PM
How would I setup the total views for the entire forum? I would think it would be some sort of mofication of this code which I found in index.php:

// get total posts
$countposts=$DB_site->query_first('SELECT COUNT(*) AS posts FROM post');
$totalposts=$countposts['posts'];
if ($totalposts=='') {
$totalposts=0;
}

I tried playing around with it a little, but couldn't figure it out.

Can anybody help me out? It should be an easy hack, but not positive.

03-07-2001, 03:45 PM
If you want to count all the posts for a single forum, use this: $forumposts = $DB_site->query_first("
SELECT COUNT(postid) AS posts
FROM post
LEFT JOIN thread ON (thread.threadid = post.threadid)
WHERE thread.forumid=\"$forumid\"");
$totalposts = number_format($forumposts[posts]); and if you want to count all the posts for the entire board, use this: $boardposts = $DB_site->query_first("
SELECT COUNT(postid) AS posts FROM post");
$totalposts = number_format($boardposts[posts]); Hope this helps.

03-07-2001, 03:51 PM
Oops, I just noticed that you said that you wanted total ~views~ so here is the code for that: $boardviews = $DB_site->query_first("
SELECT SUM(views) AS threadviews FROM thread");
$totalviews = number_format($boardviews[threadviews]);

03-07-2001, 03:57 PM
Kier, he wants total views not posts but think it will be based on posts, which it will not :) because views are stored in the thread table so you would have to add all the views for every thread together.




$forumviews = $DB_site->query_first("
SELECT views
FROM thread
WHERE threadid > 0);

while ($forumviews2 = mysql_fetch_array($forumviews)) {

$threadviews = $forumviews2["views"];
$totalviews = $totalviews+ $threadviews;
}



Now:

i) i think that will work but i have not tested it
ii) i would also think it is quite server intensive as it has to go through every single thread to count up. I can't see any other way of doing it bar having a counter increase every time a thread is viewed at the same time the thread count is increased. That would be possible and perhaps less server intensive in the end.
iii) if it does not work tell me, someone will probably post glaring errors.

03-07-2001, 03:58 PM
ar.. kier re posted and that looks a far far better way of doing it, something new to learn :)

03-07-2001, 04:00 PM
Hehe, I've never actually used the mySQL SUM() function before, but i figured it might exist/work, and it did! Now to go back to my site and do some optimising :rolleyes: ;)

03-07-2001, 04:33 PM
All I have to say is shweeeeeeeeeeeeeeet

You da man Kier!

Ninboy
05-25-2001, 10:21 PM
Oks, where say $forumposts = $DB_site->query_first("
SELECT COUNT(postid) AS posts
FROM post
LEFT JOIN thread ON (thread.threadid = post.threadid)
WHERE thread.forumid=\"$forumid\"");
$totalposts = number_format($forumposts[posts]);
In the thread.forumid=\"$forumid\""); I need to put the forum id?

eva2000
05-25-2001, 10:29 PM
Originally posted by Ninboy
Oks, where say
In the I need to put the forum id? a releeased hack is here http://vbulletin.com/forum/showthread.php?s=&threadid=14739