vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Query help in forumdisplay.php (https://vborg.vbsupport.ru/showthread.php?t=219934)

Antivirus 08-01-2009 12:40 AM

Query help in forumdisplay.php
 
1 Attachment(s)
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.

Antivirus 08-01-2009 01:28 AM

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*


All times are GMT. The time now is 10:00 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.01078 seconds
  • Memory Usage 1,720KB
  • 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
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)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