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

Reply
 
Thread Tools Display Modes
  #101  
Old 10-23-2012, 03:37 AM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Dangit ... I knew I didn't fully understand the JOINs ...

The subscribethread table doesn't have an email column, but if I JOIN the user table I don't have to mention the email table (in the JOIN) in order to use it in the UPDATE ... WHERE as long as the userid from the user table matches the userid from subscribethread table?
Reply With Quote
  #102  
Old 10-23-2012, 02:37 PM
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
Dangit ... I knew I didn't fully understand the JOINs ...

The subscribethread table doesn't have an email column, but if I JOIN the user table I don't have to mention the email table (in the JOIN) in order to use it in the UPDATE ... WHERE as long as the userid from the user table matches the userid from subscribethread table?
What's the point of the email address in the query? Since you have a users userid, in the $id variable, that will uniquely identify everything you need to update the appropriate stuff in the subscriptionthread table.

If what I understand you want to achieve why not use the following query:

PHP Code:
 $db->query("UPDATE " .TABLE_PREFIX"subscribethread
                   SET emailupdate = 0
                   WHERE emailupdate IN (1,2,3)
                   AND userid = 
$id"); 
Also note two things, first your $db->query should use () not {} and have a ; at the end, and also an update query can only be applied to a table and not a join.
Reply With Quote
  #103  
Old 10-23-2012, 05:22 PM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok so JOINs can't be used in an UPDATE? I don't recall reading that anywhere

The reason I'm trying to include the email field is that if I don't it trips an error further along the mod about not inputting a valid email and doesn't complete the query.

Code:
        // If an email isn't entered or is invalid show this error
        if (empty($unsubscribe['email']))
        {
            eval(standard_error(fetch_error('advanced_unsubscribe_link_error_unsubscribed', $vbulletin->options['contactuslink'])));
        }
How I understand that code it checks each query for an email address and if the query doesn't have one it spits out the error. I have a couple of ideas about how to get around that (move the code so it comes before the queries that don't have email fields, or just not use it ) but not sure if there's a better way.

I do use ( for the $db->queries and they do have the ; at the end
Reply With Quote
  #104  
Old 11-05-2012, 09:55 PM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok so I sorta started working on this again, and I can't figure out what's wrong here. I'm trying to copy the rows from subscribethread to unsub_subscribethread *yes it does exist*. Yes the option is selected in the ACP. The mod runs but doesn't spit out ANY errors, it also doesn't copy the rows

This is the select query I'm using

Code:
  $unsubscribe = $db->query_read("SELECT NULL, userid, threadid, emailupdate, folderid, canview FROM " .TABLE_PREFIX. "subscribethread WHERE userid = '$id' AND emailupdate IN (1, 2,3)");
This is the code inside of the function


Code:
     // If you selected to backup existing thread subscriptions this code will be exectued.
     if ($vbulletin->options['advanced_unsubscribe_link_thread_sub_backup'])
        {
        // Copies existing thread subscriptions to the unsub_subscribethread table.
           $db->query("
                    INSERT INTO " .TABLE_PREFIX. "unsub_subscribethread
                    SELECT NULL,
                           userid,
                           threadid,
                           emailupdate,
                           folderid,
                           canview
                    FROM " .TABLE_PREFIX. "subscribethread
                    WHERE userid = '$id'
                    AND emailupdate IN (1, 2, 3)");
        }
If I run this query in phpmyadmin it works ...

Code:
                    INSERT INTO unsub_subscribethread
                    SELECT NULL,
                           userid,
                           threadid,
                           emailupdate,
                           folderid,
                           canview
                    FROM subscribethread
                    WHERE userid = 1
                    AND emailupdate IN (1, 2, 3)
Reply With Quote
  #105  
Old 11-05-2012, 10:15 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Are you sure $id has the right value?
Reply With Quote
  #106  
Old 11-05-2012, 10:19 PM
TheSupportForum TheSupportForum is offline
 
Join Date: Jan 2007
Posts: 1,158
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by John Lester View Post
Ok so I sorta started working on this again, and I can't figure out what's wrong here. I'm trying to copy the rows from subscribethread to unsub_subscribethread *yes it does exist*. Yes the option is selected in the ACP. The mod runs but doesn't spit out ANY errors, it also doesn't copy the rows

This is the select query I'm using

Code:
  $unsubscribe = $db->query_read("SELECT NULL, userid, threadid, emailupdate, folderid, canview FROM " .TABLE_PREFIX. "subscribethread WHERE userid = '$id' AND emailupdate IN (1, 2,3)");
This is the code inside of the function

for example where is

Code:
     // If you selected to backup existing thread subscriptions this code will be exectued.
     if ($vbulletin->options['advanced_unsubscribe_link_thread_sub_backup'])
        {
        // Copies existing thread subscriptions to the unsub_subscribethread table.
           $db->query("
                    INSERT INTO " .TABLE_PREFIX. "unsub_subscribethread
                    SELECT NULL,
                           userid,
                           threadid,
                           emailupdate,
                           folderid,
                           canview
                    FROM " .TABLE_PREFIX. "subscribethread
                    WHERE userid = '$id'
                    AND emailupdate IN (1, 2, 3)");
        }
If I run this query in phpmyadmin it works ...

Code:
                    INSERT INTO unsub_subscribethread
                    SELECT NULL,
                           userid,
                           threadid,
                           emailupdate,
                           folderid,
                           canview
                    FROM subscribethread
                    WHERE userid = 1
                    AND emailupdate IN (1, 2, 3)

you havent registered the variable


$unsubscribe

here is an example of how to do so

$templater = vB_Template::create('unsubscribe');
$templater->register('$unsubscribe', $unsubscribe);
$template_hook[forumhome_wgo_pos2] .= $templater->render();

you will then need to call $unsubscribe in a template which will display the content from the query remembering to change the $template_hook

you will then need to place {vb:raw unsubscribe}
in template unsubscribe

as long as you place the correct hook location with the correct template hook the query will show in the hook location you selected
Reply With Quote
  #107  
Old 11-06-2012, 07:46 AM
John Lester John Lester is offline
 
Join Date: Nov 2004
Posts: 543
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh great now I'm even more confused ... this mod uses misc.php?do=unsubscribe as the url. In the mod a basic template is "built" and all of the other code executes fine (so far). I have a few more select queries structured like the one I posted earlier ... they seem to work just fine.

So now I'm wondering ... is the mod even executing those select queries? If it's working as is now (aside from the code in question) do I still need to tie it into a hook?

Keep in mind I'm a complete novice at this, all I'm doing is added options to an existing mod (that was marked as reusable and updated for 4.x by kh99).

Just for shits n giggles I'm going to attach what I have so far, if someone would be kind enough to look at it and tell me if there's a better way to go about doing this I might as well find out now and switch gears
Attached Files
File Type: xml product-advanced_unsubscribe_link_1.0.xml (31.9 KB, 1 views)
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 05:01 PM.


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.15059 seconds
  • Memory Usage 2,257KB
  • 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
  • (1)bbcode_php
  • (2)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
  • (2)pagenav_pagelink
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (1)postbit_attachment
  • (7)postbit_onlinestatus
  • (7)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