Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > General > Member Archives

Reply
 
Thread Tools
LEFT JOIN question... Details »»
LEFT JOIN question...
Version: , by TECK TECK is offline
Developer Last Online: Nov 2023 Show Printable Version Email this Page

Version: Unknown Rating:
Released: 09-26-2002 Last Update: Never Installs: 0
 
No support by the author.

i have this query:
Code:
$threads=$DB_site->query("
  SELECT * FROM thread WHERE open=1 AND open<>10 ORDER BY lastpost DESC
");
while ($thread=$DB_site->fetch_array($threads)) {
what i try to do is to associate with the $thread[userid] it's actual usergroupid. so i need to find a way to enter something like that:
Code:
if ($thread[pollid] and in_array($user[usergroupid], array(5, 6))) {
instead of:
Code:
if ($thread[pollid] and in_array($thread[postuserid], array(1, 5))) {
without adding a query. there is a way... using a JOIN.
what is the best aproach? thanks for reading this.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #12  
Old 09-27-2002, 05:32 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by TECK
do you think is worth adding a poll on the home page? just to spice up the look? most portals have that... although my homepage will not look at all like a portal.
i think it's not worth..
i don't understand why everyone wnats to have a poll on his portal..
Reply With Quote
  #13  
Old 09-27-2002, 05:35 PM
TECK's Avatar
TECK TECK is offline
 
Join Date: Nov 2001
Location: Canada
Posts: 4,182
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i also think like that stefan... i'm curious what others think about it?
btw, i disabled polls on my forums.. it boosts the queries to 22!!! from 17-18.... holly molly!!
Reply With Quote
  #14  
Old 09-27-2002, 06:06 PM
TECK's Avatar
TECK TECK is offline
 
Join Date: Nov 2001
Location: Canada
Posts: 4,182
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ok i was thinking of this piece of code for forumhome:
Code:
$threadpolls = $DB_site->query("
  SELECT * FROM thread LEFT JOIN poll USING(pollid) WHERE visible=1 AND open<>10 $iforumperms ORDER BY threadid DESC
");
while ($threadpoll=$DB_site->fetch_array($threadpolls)) {
  $pollid=$threadpoll[pollid];
  $pollinfo=$DB_site->query_first("SELECT * FROM poll WHERE pollid='$pollid'");

  $pollinfo[question]=bbcodeparse($pollinfo[question],$threadpoll[forumid],1);
  ... <more code here
can i skip the extra $pollinfo query? what is the best way to insert it in $threadpolls?
i use a SUM? i'm not sure...
Reply With Quote
  #15  
Old 09-27-2002, 06:12 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

you have a query in a while loop???
not god not good

but normally this query
Code:
$threadpolls = $DB_site->query("
  SELECT thread.*,poll.* FROM thread LEFT JOIN poll USING(pollid) WHERE visible=1 AND open<>10 $iforumperms ORDER BY threadid DESC
");
is enough, you don't need the extra pollinfo query then..
Reply With Quote
  #16  
Old 09-27-2002, 06:21 PM
TECK's Avatar
TECK TECK is offline
 
Join Date: Nov 2001
Location: Canada
Posts: 4,182
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

aha.. i saw the loop that's why i wanted to make sure the way i placed properly the LEFT JOIN.
i left unchanged the code from showthread.php just to get a better idea how i want to insert it onto foreumhome index.php.

so everything is $pollinfo can be replaced with $threadpoll and it will work.. thanks alot stefan for your help..
Reply With Quote
  #17  
Old 09-27-2002, 06:28 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yes it'll work with $threadpoll

you're welcome floren.
Reply With Quote
  #18  
Old 09-27-2002, 08:52 PM
TECK's Avatar
TECK TECK is offline
 
Join Date: Nov 2001
Location: Canada
Posts: 4,182
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hmm how do i put a AND to grab only the threads with polls on it?
Code:
$polls = $DB_site->query("
  SELECT thread.*,poll.* FROM thread LEFT JOIN poll USING (pollid) WHERE visible=1 AND open<>10 $iforumperms ORDER BY threadid DESC
");
while ($poll=$DB_site->fetch_array($polls)) {
Reply With Quote
  #19  
Old 09-27-2002, 10:47 PM
Scott MacVicar Scott MacVicar is offline
 
Join Date: Oct 2001
Location: Glasgow, Scotland
Posts: 1,199
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Its not about the number of queries btw

1 big query that joins say 4 or more tables could take more time to execute than 4 seperate queries to each of the tables.
Reply With Quote
  #20  
Old 09-28-2002, 12:49 AM
Erwin's Avatar
Erwin Erwin is offline
 
Join Date: Jan 2002
Posts: 7,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Having polls on the homepage is more complicated than that. Do you want just results, or the actual voting as well? If you want the ability to vote as well, you need to figure out if the user has voted or not. Also, need to know if the poll is open or closed. I adapted wa jones' poll to be used on my site. It works quite well. 2 queries when the user hasn't voted, and 3 queries when they user votes. (From memory).
Reply With Quote
  #21  
Old 09-28-2002, 04:04 AM
TECK's Avatar
TECK TECK is offline
 
Join Date: Nov 2001
Location: Canada
Posts: 4,182
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i got it working:
Code:
if ($poll=$DB_site->query_first("
  SELECT * FROM thread LEFT JOIN poll USING (pollid) WHERE visible=1 AND open<>10 $ ipollperms $iforumperms ORDER BY thread.pollid DESC LIMIT 1
")) {
thanks guys.

now, the way it goes is like that: if the user have permissions to post a poll, it will grab it from no matter what thread you post it and display it on forumhome. if a new poll is posted, the current poll is automatically replaced with the new one.
my hack adds only 2 queries, voted or not voted. that brings my forumhome page to a total of 15queries... i think i can live with that...

here it is what it looks like, not voted:
Attached Files
File Type: (21.4 KB, 16 views)
Reply With Quote
Reply

Thread Tools

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:46 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.04966 seconds
  • Memory Usage 2,324KB
  • Queries Executed 26 (?)
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
  • (7)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (1)postbit_attachment
  • (11)postbit_onlinestatus
  • (11)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
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete