Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-07-2001, 03:24 PM
SystemLogic SystemLogic is offline
 
Join Date: Nov 2001
Posts: 68
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #2  
Old 03-07-2001, 03:45 PM
Guest
 
Posts: n/a
Default

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.
Reply With Quote
  #3  
Old 03-07-2001, 03:51 PM
Guest
 
Posts: n/a
Default

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]); 
Reply With Quote
  #4  
Old 03-07-2001, 03:57 PM
Guest
 
Posts: n/a
Default

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.
Reply With Quote
  #5  
Old 03-07-2001, 03:58 PM
Guest
 
Posts: n/a
Default

ar.. kier re posted and that looks a far far better way of doing it, something new to learn
Reply With Quote
  #6  
Old 03-07-2001, 04:00 PM
Guest
 
Posts: n/a
Default

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
Reply With Quote
  #7  
Old 03-07-2001, 04:33 PM
Guest
 
Posts: n/a
Default

All I have to say is shweeeeeeeeeeeeeeet

You da man Kier!
Reply With Quote
  #8  
Old 05-25-2001, 10:21 PM
Ninboy
Guest
 
Posts: n/a
Default

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?
Reply With Quote
  #9  
Old 05-25-2001, 10:29 PM
eva2000's Avatar
eva2000 eva2000 is offline
 
Join Date: Oct 2001
Location: Brisbane, Australia
Posts: 577
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:06 PM.


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.04345 seconds
  • Memory Usage 2,237KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (5)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (2)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete