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

Reply
 
Thread Tools Display Modes
  #1  
Old 05-10-2015, 01:29 AM
ne_one ne_one is offline
 
Join Date: Nov 2013
Posts: 21
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default SQL query question - returning threads by forum id

I have a WordPress plugin that retrieves the most recent vB threads. However, it's not quite working as expected and the developer has moved on.

The plugin has a parameter to limit the scope by passing a list of forum ids. When the parameter isn't specified, all forums are considered and data is returned. When populated with known forum ids, it doesn't return any data.

Here's the query:

Code:
SELECT t.threadid, t.lastposterid, t.lastposter, FROM_UNIXTIME(t.lastpost) as lastposttime, t.replycount, t.views, t.title, u.avatarid, u.avatarrevision, p.pagetext, NOT ISNULL(av.userid) as hascustomavatar FROM vb4_thread AS t INNER JOIN vb4_forum AS f ON f.forumid = t.forumid INNER JOIN vb4_user AS u ON u.userid = t.lastposterid INNER JOIN vb4_post AS p ON p.postid = t.lastpostid LEFT JOIN vb4_customavatar AS av ON av.userid = u.userid WHERE t.replycount != 0 AND f.forumid IN ( 1,2,3 ) AND visible="1" ORDER BY t.lastpost DESC LIMIT 10

The SQL syntax appears to be ok. Is the forum qualifier correct?

Thanks for your help!
Reply With Quote
  #2  
Old 05-10-2015, 04:24 AM
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Location: Phoenix, Az. USA
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There is a typo in your query. visible should be t.visible
Code:
SELECT t.threadid, t.lastposterid, t.lastposter, FROM_UNIXTIME(t.lastpost) as lastposttime, t.replycount, t.views, t.title, u.avatarid, u.avatarrevision, p.pagetext, NOT ISNULL(av.userid) as hascustomavatar FROM vb4_thread AS t INNER JOIN vb4_forum AS f ON f.forumid = t.forumid INNER JOIN vb4_user AS u ON u.userid = t.lastposterid INNER JOIN vb4_post AS p ON p.postid = t.lastpostid LEFT JOIN vb4_customavatar AS av ON av.userid = u.userid WHERE t.replycount != 0 AND f.forumid IN ( 1,2,3 ) AND t.visible="1" ORDER BY t.lastpost DESC LIMIT 10
From what I can tell with a couple test runs, your forum numbers 1,2,3 don't have threads in them. If you specify forumid's with threads, it has a return. This query selects all forums that have threads.

Code:
SELECT t.threadid, t.lastposterid, t.lastposter, FROM_UNIXTIME(t.lastpost) as lastposttime, t.replycount, t.views, t.title, u.avatarid, u.avatarrevision, p.pagetext, NOT ISNULL(av.userid) as hascustomavatar FROM thread AS t INNER JOIN forum AS f ON f.forumid = t.forumid INNER JOIN user AS u ON u.userid = t.lastposterid INNER JOIN post AS p ON p.postid = t.lastpostid LEFT JOIN customavatar AS av ON av.userid = u.userid WHERE t.replycount != 0 AND f.forumid in (select forumid from thread group by forumid)  AND t.visible="1" ORDER BY t.lastpost DESC LIMIT 10;
As to the accuracy of the query, I could check that as my VB4 forum is a private VB5 > VB4 test/development environment. The easiest way to test it would be to post 11 new threads in different forums and run the query. The first thread you posted shouldn't come up in the query.
Reply With Quote
Благодарность от:
MarkFL
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 06:02 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.03507 seconds
  • Memory Usage 2,175KB
  • 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
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (1)post_thanks_box_bit
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (2)post_thanks_postbit_info
  • (2)postbit
  • (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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete