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 08-01-2009, 12:40 AM
Antivirus's Avatar
Antivirus Antivirus is offline
 
Join Date: Sep 2004
Location: Black Lagoon
Posts: 1,090
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Query help in forumdisplay.php

I have a mod I've written that modifies the threads shown in forumdisplay for a particular forumid. My problem however isn't with the threads which are queried, but the problem lies with navigating multiple pages.

Incorrect values are passed to the $limitlower, $limitupper, and $totalthreads vars, which basically either cause the pagenav to no longer show, or give the incorrect values to the "showing threads 1 to 1 of 1" phrase.

I have narrowed it down to the threadscount query which is run before the threadids query and the main query. Basically, the unmodified threadscount query looks something like this:

PHP Code:
SELECT COUNT(*) AS threadsAS newthread
    $hook_query_fields
FROM thread 
AS thread
    $hook_query_joins
WHERE forumid 
34
    
AND sticky 0
    $hook_query_where 
the result of this query is shown in the attached image 'query1.jpg'


After my plugin code inserted at hook: 'forumdisplay_query_threadscount' the query looks like this:
PHP Code:
SELECT COUNT(*) AS threadsAS newthread
FROM thread 
AS thread
    LEFT JOIN post 
AS p ON (p.postid thread.firstpostid)
    
LEFT JOIN sc_postgroup AS sc_pg ON (sc_pg.postid p.postid)
    
LEFT JOIN socialgroup AS sg ON (sg.groupid sc_pg.groupid)
    
LEFT JOIN sc_status AS sc_status ON (sc_status.statusid p.sc_statusid)
WHERE forumid 34
    
AND sticky 
the result of the modified query is shown in the attached image 'query2.jpg'

As you can see, the end result is now grouping the incorrect way - as there are 16 results counted (as opposed to 10 as there should be).

I am pretty sure it's due to the way COUNT() is interacting with the type of JOINS I am using in the modified query, however I am not too familiar with the logic of RIGHT, INNER, OUTER, if this is indeed the problem, etc...

Any ideas here? I have been trying different types of joins, however i might be missing the correct combination.
Attached Images
File Type: jpg query1.jpg (23.0 KB, 0 views)
File Type: jpg query2.jpg (23.2 KB, 0 views)
Reply With Quote
  #2  
Old 08-01-2009, 01:28 AM
Antivirus's Avatar
Antivirus Antivirus is offline
 
Join Date: Sep 2004
Location: Black Lagoon
Posts: 1,090
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ok - i have definitely narrowed it down to somethign to do with this JOIN in particular:

LEFT JOIN sc_postgroup AS sc_pg ON (sc_pg.postid = p.postid)


There are sometime 0 or more records in sc_postgroup with the same postid. I need this here though because users are only able to see threads that are associated with the socialgroups they have joined. Maybe this JOiN should be replaced with a subquery?

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

*solved, please disregard*
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:45 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03996 seconds
  • Memory Usage 2,195KB
  • Queries Executed 12 (?)
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)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit_info
  • (2)postbit
  • (2)postbit_attachment
  • (2)postbit_onlinestatus
  • (2)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_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete