Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions

Reply
 
Thread Tools Display Modes
  #91  
Old 10-01-2012, 07:21 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are you getting an sql syntax error or a php syntax error?

You're trying to select the rows from subscribethread for only one user so you really only need to check the usergroupid and either do the query or not. If you don't have the usergroupid for that user available then you do save one query by combining it like that, but since this is for something that is executed rarely compared to everything going on on the forum, it might be a better idea to do two separate queries and have the code be less complicated.

Having said all that, the way you have it is doing a join to the UPDATE query, but the WHERE goes with the select, so it will probably tell you that there's no column named 'usergroupid'. Maybe you should do this instead:

Code:
INSERT INTO " .TABLE_PREFIX. "unsub_subscribethread AS unsub_subscribethread
                SELECT NULL,
                       userid,
                       threadid,
                       emailupdate,
                       folderid,
                       canview
                FROM " .TABLE_PREFIX. "subscribethread
                LEFT JOIN " .TABLE_PREFIX. "user AS user ON (user.userid = unsub_subscribethread.userid)
                WHERE userid = '$id'
                AND emailupdate IN (1, 2, 3)
                AND usergroupid NOT IN (5, 6, 7)
Reply With Quote
  #92  
Old 10-02-2012, 03:44 AM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmmm so it would be better to run the check before executing any of the queries (I was planning on excluding those user groups from each query) instead of building the conditional into the query? I suppose I should go a step further and create a setting to allow admins to exclude certain user groups, what do you guys think?

My thinking was that since the subscribethread table doesn't have the usergroupid column, that I needed to call if from the user table. But I don't see why you went with user.userid = unsub_subscribethread.userid?

I'm pretty much stalling on this due to the fact that I just can't seem to wrap my head around the proper loop. I've done some reading and I've searched for examples, but nothing I have found seems to have "clicked" with my brain yet
Reply With Quote
  #93  
Old 10-02-2012, 09:05 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by John Lester View Post
Hmmm so it would be better to run the check before executing any of the queries (I was planning on excluding those user groups from each query) instead of building the conditional into the query? I suppose I should go a step further and create a setting to allow admins to exclude certain user groups, what do you guys think?
Yeah, something like that sounds better to me.

Quote:
My thinking was that since the subscribethread table doesn't have the usergroupid column, that I needed to call if from the user table. But I don't see why you went with user.userid = unsub_subscribethread.userid?
When you do a join with an 'ON', the condition in the ON needs to be true for the rows that get joined. In your case, it needs to compare userids so the parts of the joined rows are for the same user (otherwise the results don't make a lot of sense). The 'ON' doesn't affect which columns appear in the results.


Quote:
I'm pretty much stalling on this due to the fact that I just can't seem to wrap my head around the proper loop. I've done some reading and I've searched for examples, but nothing I have found seems to have "clicked" with my brain yet
I'm sorry I dumped this on you. I keep hoping maybe I'll get back to it, but instead I just keep piling up other mods that are half done. But I can certainly help with things like getting loops to work if you want.
Reply With Quote
  #94  
Old 10-03-2012, 02:01 PM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Don't worry about dumping this on me, I'll eventually either figure out the loop or ask you to figure it out for me

Your reason for editing the post has me intrigued

Now back to the JOIN statement just for clarification since I'm almost done setting up the exclude user groups settings

user.userid = unsub_subscribethread.userid ... I thought that this would only pull the userid from the user table, hence my confusion. The entire point of joining the user table was to grab the usergroupid for use in checking user groups in the query. I am assuming that is how JOIN works (grabbing only the column listed in the ()'s ) but I also assumed that I would be done with this mod by now
Reply With Quote
  #95  
Old 10-03-2012, 02:38 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by John Lester View Post
Your reason for editing the post has me intrigued
Yeah, that's my way of saying I made so many typos or other mistakes that part of it was almost unreadable.


Quote:
user.userid = unsub_subscribethread.userid ... I thought that this would only pull the userid from the user table, hence my confusion. The entire point of joining the user table was to grab the usergroupid for use in checking user groups in the query. I am assuming that is how JOIN works (grabbing only the column listed in the ()'s ) but I also assumed that I would be done with this mod by now
You're really creating a "virtual" table that you're selecting from, and the ON is just instructions on how to do that. You still need to list any columns you want returned (from either table) after SELECT. I didn't list user.usegroupid in the code I posted above because I only used it in the WHERE and didn't think there was any need to include it in the returned data.
Reply With Quote
  #96  
Old 10-03-2012, 04:15 PM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

AH I see what happened here, you were referring to the code I pasted (#86) showing a failed attempt at looping

I should've mentioned that I scrapped that bit of code and my question regarding the LEFT JOIN was for the code in post #89

But it's a moot point now, I get the gist of what you were saying in regards to the LEFT JOIN
Reply With Quote
  #97  
Old 10-22-2012, 05:59 PM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm getting a parse error when I have this code un-commented, I suspect it's the LEFT JOIN but then again what do I know

I'm trying to join the user table to pull the email column so the mod doesn't return the email error if there is no email column in the table.

Code:
    // If you selected to change existing thread subscriptions this code will be executed
    if ($vbulletin->options['advanced_unsubscribe_link_existing_thread_sub'])
       {
         // Sets existing thread subscriptions to through control panel only
         $db->query{"
                   UPDATE " .TABLE_PREFIX. "subscribethread
                   LEFT JOIN " .TABLE_PREFIX. "user AS user ON (user.email = user.userid)
                   SET emailupdate = 0
                   WHERE emailupdate IN (1,2,3)
                   AND userid = $id
                   AND email= '" . $db->escape_string($email) . "'");
       }
Reply With Quote
  #98  
Old 10-22-2012, 06:02 PM
squidsk's Avatar
squidsk squidsk is offline
 
Join Date: Nov 2010
Posts: 969
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Your ON clause is wrong, one of the fields needs to be from the subscribethread table.
Reply With Quote
  #99  
Old 10-22-2012, 07:42 PM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for replying squid I changed the ON clause and still have a parse error

Code:
    // If you selected to change existing thread subscriptions this code will be executed
    if ($vbulletin->options['advanced_unsubscribe_link_existing_thread_sub'])
       {
         // Sets existing thread subscriptions to through control panel only
         $db->query{"
                   UPDATE " .TABLE_PREFIX. "subscribethread
                   LEFT JOIN " .TABLE_PREFIX. "user AS user ON (subscribethread.userid = user.email)
                   SET emailupdate = 0
                   WHERE emailupdate IN (1,2,3)
                   AND userid = $id
                   AND email= '" . $db->escape_string($email) . "'");
       }
Tried using this as well and get a parse error.

Code:
(user.email = subscribethread.userid)
If I comment out the block of code the mod works fine.
Reply With Quote
  #100  
Old 10-23-2012, 01:12 AM
squidsk's Avatar
squidsk squidsk is offline
 
Join Date: Nov 2010
Posts: 969
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by John Lester View Post
Thanks for replying squid I changed the ON clause and still have a parse error

Code:
    // If you selected to change existing thread subscriptions this code will be executed
    if ($vbulletin->options['advanced_unsubscribe_link_existing_thread_sub'])
       {
         // Sets existing thread subscriptions to through control panel only
         $db->query{"
                   UPDATE " .TABLE_PREFIX. "subscribethread
                   LEFT JOIN " .TABLE_PREFIX. "user AS user ON (subscribethread.userid = user.email)
                   SET emailupdate = 0
                   WHERE emailupdate IN (1,2,3)
                   AND userid = $id
                   AND email= '" . $db->escape_string($email) . "'");
       }
Tried using this as well and get a parse error.

Code:
(user.email = subscribethread.userid)
If I comment out the block of code the mod works fine.
Shouldn't the ON block be:

Code:
ON user.userid = subscribethread.userid
You can't compare an email to a userid.
Reply With Quote
Reply

Thread Tools
Display Modes

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 07:12 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.05357 seconds
  • Memory Usage 2,281KB
  • 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
  • (7)bbcode_code
  • (6)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete