vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Total Views For Forum (https://vborg.vbsupport.ru/showthread.php?t=10709)

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:

Code:

// 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:
PHP Code:

$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:
PHP Code:

$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:
PHP Code:

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


PHP Code:


$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
Quote:

PHP Code:

$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
Quote:

thread.forumid=\"$forumid\"");
I need to put the forum id?

eva2000 05-25-2001 10:29 PM

Quote:

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/showthrea...threadid=14739


All times are GMT. The time now is 02:29 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01159 seconds
  • Memory Usage 1,739KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (5)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete