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

Reply
 
Thread Tools Display Modes
  #1  
Old 11-24-2008, 12:55 PM
Taurine Taurine is offline
 
Join Date: Dec 2006
Location: Illinois
Posts: 9
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Count New posts in one forum?

Is there any way to count new posts in one forum and have it displayed as a number?

I'm trying to set up a new control block for the officers of in my Guild and I wanted to have it displayed similar to the welcome block for vbadvanced.

New News:2
New Applicants:5
etc......

But I need to be able to count the posts in individual forums.... Any help would be great.
Reply With Quote
  #2  
Old 11-24-2008, 02:25 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sure you could. If you do it the easy way and just add a query in a plugin. If you are only displaying it on one page for the user, then that is probably not a big deal, but if you diplay it in the postbit (showthread) then that means one query added per postbit on each showthread. Default number of posts per thread is 20 (I think), so that is 20 extra queries per page. Not good. What you really should do is write a plugin that update a column in the user table (or another new table) for the forums you want to keep track of. You'd have to update it when posts are made, posts are deleted, posts are moved out of the forums, posts are merged, etc. But, if you don't want it in the postbit and only on a single page, writing a plugin with one query is probably not a big deal. If this is for a vbadvanced page though, you should probably ask over there for help cuz they are better able to suggest hook locations and template modifications.
Reply With Quote
  #3  
Old 11-24-2008, 11:34 PM
Taurine Taurine is offline
 
Join Date: Dec 2006
Location: Illinois
Posts: 9
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It is for vbadvanced, but I have gotten no response on my question there so I figured I'd ask here.

A query was the way i figured I'd go, but I'm having trouble with that as it's a very weak point on my limited coding knowledge. I was hoping that using a modified version of the default vbadvanced one that gets the total new posts would do the trick. I think it would be as simple as defining a forumid...... but thats where i'm lost.

Here is the current query for getting a total count of all the forums:
PHP Code:
    // New posts
    
if ($mod_options['portal_welcome_newposts'])
    {
        if (
strlen($vbulletin->session->vars['newposts']) > AND !$vbulletin->options['threadmarking'])
        {
            
$newposts number_format($vbulletin->session->vars['newposts']);
        }
        else
        {
            
$getnewposts $db->query_first("
                SELECT COUNT(*) AS count
                FROM " 
TABLE_PREFIX "post AS post
                " 
iif($vbulletin->options['threadmarking'],
                    
'LEFT JOIN ' TABLE_PREFIX 'threadread AS threadread ON (threadread.threadid = post.threadid AND threadread.userid = ' $vbulletin->userinfo['userid'] . ')') . "
                WHERE dateline >= " 
$vbulletin->userinfo['lastvisit'] .
                    
iif($vbulletin->options['threadmarking'],
                        
' AND dateline > IF(threadread.readtime IS NULL, ' . (TIMENOW - ($vbulletin->options['markinglimit'] * 86400)) . ', threadread.readtime)') . "
                    AND visible = 1
            "
);

            if (!
$vbulletin->options['threadmarking'])
            {
                
$db->query_write("UPDATE " TABLE_PREFIX "session SET newposts = '$getnewposts[count]' WHERE userid = " $vbulletin->userinfo['userid']);
            }

            
$newposts vb_number_format($getnewposts['count']); 
I figured by changing the variable $newpost to $newnews and $newapps etc..... I could use the same query for each of the different outputs I wanted.

The only other thing I was thinking was getting it so it just counted new threads instead of posts, but i'd be happy with either.

Any help would be great!

--------------- Added [DATE]1227576934[/DATE] at [TIME]1227576934[/TIME] ---------------

I should add that I have the template written out, the queries are the only spot I'm stuck on right now.
Reply With Quote
  #4  
Old 12-03-2008, 02:35 AM
Taurine Taurine is offline
 
Join Date: Dec 2006
Location: Illinois
Posts: 9
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Anyone have any ideas?
Reply With Quote
  #5  
Old 12-03-2008, 03:37 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Why are you updating the session table? You realize that gets wiped shortly after the user leaves the site. Also, there is no column newposts in the session table (unless you added it?), so that query is not going to do anything.
Reply With Quote
  #6  
Old 12-03-2008, 12:18 PM
Taurine Taurine is offline
 
Join Date: Dec 2006
Location: Illinois
Posts: 9
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
Why are you updating the session table? You realize that gets wiped shortly after the user leaves the site. Also, there is no column newposts in the session table (unless you added it?), so that query is not going to do anything.
That's the default query for vbadvanced to get the new post count since your last visit. the problem i'm having is that it counts all new posts, and I need ones in just one forum. I tried adding a forumid condition but with no success.
Reply With Quote
  #7  
Old 12-03-2008, 02:04 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Post what you tried to change it to (with the forumid) and maybe we can spot the error.
Reply With Quote
  #8  
Old 12-03-2008, 11:45 PM
Taurine Taurine is offline
 
Join Date: Dec 2006
Location: Illinois
Posts: 9
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code I tried:

PHP Code:

                
{
            
$getnewapps $db->query_first("
                SELECT COUNT(*) AS count
                FROM " 
TABLE_PREFIX "post AS post
                " 
iif($vbulletin->options['threadmarking'],
                    
'LEFT JOIN ' TABLE_PREFIX 'threadread AS threadread ON (threadread.threadid = post.threadid AND threadread.userid = ' $vbulletin->userinfo['userid'] . ')') . "
                WHERE forumid = 38 AND dateline >= " 
$vbulletin->userinfo['lastvisit'] .
                    
iif($vbulletin->options['threadmarking'],
                        
' AND dateline > IF(threadread.readtime IS NULL, ' . (TIMENOW - ($vbulletin->options['markinglimit'] * 86400)) . ', threadread.readtime)') . "
                    AND visible = 1
            "
);

            if (!
$vbulletin->options['threadmarking'])
            {
                
$db->query_write("UPDATE " TABLE_PREFIX "session SET newposts = '$getnewapps[count]' WHERE userid = " $vbulletin->userinfo['userid']);
            }

            
$newapps vb_number_format($getnewapps['count']);
        } 



Database error in vBulletin 3.7.2:

Invalid SQL:

SELECT COUNT(*) AS count
FROM imperialpost AS post

WHERE forumid = 38 AND dateline >= 1228313329
AND visible = 1;

MySQL Error : Unknown column 'forumid' in 'where clause'
Error Number : 1054
Request Date : Wednesday, December 3rd 2008 @ 07:42:31 PM
Error Date : Wednesday, December 3rd 2008 @ 07:42:31 PM
Script : http://www.fooguild.com/
Referrer : http://www.fooguild.com/forums/forumdisplay.php?f=38
IP Address : ...............
Username : ...................
Classname : vB_Database
MySQL Version : 5.0.51a-community-log
Reply With Quote
  #9  
Old 12-04-2008, 12:17 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That's because there is no column forumid in either the post table or the threadread table. You will need to do a JOIN between the post table and the thread table (on thread.threadid = post.threadid) in order to then use thread.forumid in your where statement.
Reply With Quote
  #10  
Old 12-04-2008, 12:29 AM
Taurine Taurine is offline
 
Join Date: Dec 2006
Location: Illinois
Posts: 9
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Working now, thanks!
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 02:35 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.04126 seconds
  • Memory Usage 2,281KB
  • Queries Executed 11 (?)
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
  • (2)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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_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