vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   How to pass users pw through email? (https://vborg.vbsupport.ru/showthread.php?t=285376)

kh99 10-01-2012 07:21 PM

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)


John Lester 10-02-2012 03:44 AM

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 :D

kh99 10-02-2012 09:05 AM

Quote:

Originally Posted by John Lester (Post 2370122)
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 :D
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.

John Lester 10-03-2012 02:01 PM

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 :D

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 :D

kh99 10-03-2012 02:38 PM

Quote:

Originally Posted by John Lester (Post 2370503)
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 :D
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.

John Lester 10-03-2012 04:15 PM

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

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 :)

John Lester 10-22-2012 05:59 PM

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 :D

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) . "'");
      }


squidsk 10-22-2012 06:02 PM

Your ON clause is wrong, one of the fields needs to be from the subscribethread table.

John Lester 10-22-2012 07:42 PM

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.

squidsk 10-23-2012 01:12 AM

Quote:

Originally Posted by John Lester (Post 2375147)
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.


All times are GMT. The time now is 06:06 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.01657 seconds
  • Memory Usage 1,760KB
  • 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
  • (7)bbcode_code_printable
  • (6)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete