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

Reply
 
Thread Tools Display Modes
  #1  
Old 05-22-2011, 12:06 AM
ZERO <ibis> ZERO <ibis> is offline
 
Join Date: Dec 2007
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default [SOLVED] SQL Help

I am running into a strange problem where the function below is not working:

*Note that $userid is feeding the correct value

PHP Code:
$sbquery2 $db->query_read("
            SELECT " 
TABLE_PREFIX "user.membergroupids
            FROM " 
TABLE_PREFIX "user
            WHERE " 
TABLE_PREFIX "user.userid = $userid
        "
);
        
        
$sbrow2 $db->fetch_array($sbquery2);
        
$sbmemgroups $sbrow2['membergroupids'];
    }

    
$sbusergroups explode(","$sbmemgroups); 
I am running this on paidsub_build and paidsub_delete.

Note that the explode works fine in useradmin_update_save where it is fed
PHP Code:
$userdata->fetch_field('membergroupids'
This leads me to believe that I am doing something wrong with the sql however it does not generate any errors.

Thanks for the help
Reply With Quote
  #2  
Old 05-22-2011, 12:10 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

My guess is that the array key is TABLE_PREFIX . "user.membergroupids" and not just "membergroupids".

ETA: If that's the problem, the easiest thing to do would be to just change the first line of SQL to read "SELECT membergroupids".
Reply With Quote
  #3  
Old 05-22-2011, 12:21 AM
ZERO <ibis> ZERO <ibis> is offline
 
Join Date: Dec 2007
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I tried:

PHP Code:
$sbmemgroups $sbrow2['" . TABLE_PREFIX . "user.membergroupids']; 
and

PHP Code:
$sbmemgroups $sbrow2['user.membergroupids']; 
both did nothing and did not produce any errors.

Edit: i will try your edited fix now
Reply With Quote
  #4  
Old 05-22-2011, 12:23 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I think you'd want

Code:
$sbmemgroups = $sbrow2[TABLE_PREFIX . 'user.membergroupids'];
or else just change the first line of your SQL to be

Code:
SELECT membergroupids

or I could be wrong.
Reply With Quote
  #5  
Old 05-22-2011, 12:27 AM
ZERO <ibis> ZERO <ibis> is offline
 
Join Date: Dec 2007
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Invalid SQL:

SELECT vbb_membergroupids
FROM vbb_user
WHERE vbb_user.userid = 1;

MySQL Error : Unknown column 'vbb_membergroupids' in 'field list'

This was the error for:

PHP Code:
$sbmemgroups $sbrow2[TABLE_PREFIX 'user.membergroupids']; 
The other option does nothing.
Reply With Quote
  #6  
Old 05-22-2011, 12:28 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try this:

PHP Code:
$sbquery2 $db->query_read("
            SELECT membergroupids
            FROM " 
TABLE_PREFIX "user
            WHERE userid = 
$userid
        "
);
        
        
$sbrow2 $db->fetch_array($sbquery2);
        
$sbmemgroups $sbrow2['membergroupids'];
    }

    
$sbusergroups explode(","$sbmemgroups); 
Reply With Quote
  #7  
Old 05-22-2011, 12:32 AM
ZERO <ibis> ZERO <ibis> is offline
 
Join Date: Dec 2007
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The above did nothing. No errors either.

--------------- Added [DATE]1306027999[/DATE] at [TIME]1306027999[/TIME] ---------------

For reference the following query runs fine:

PHP Code:
$sbquery $db->query_read("
            SELECT " 
TABLE_PREFIX "userfield.field9
            FROM " 
TABLE_PREFIX "userfield
            WHERE " 
TABLE_PREFIX "userfield.userid = $userid
        "
);

        
$sbrow $db->fetch_array($sbquery);
        
$sbaid $sbrow['field9']; 
Reply With Quote
  #8  
Old 05-22-2011, 12:35 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ZERO <ibis> View Post
For reference the following query runs fine:
OK, sorry, I guess i was wrong about what the problem was. Anyone else?
Reply With Quote
  #9  
Old 05-22-2011, 12:40 AM
ZERO <ibis> ZERO <ibis> is offline
 
Join Date: Dec 2007
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Could this be the problem:

PHP Code:
foreach($sbusergroups as $sbgroup)
    {
        
$sbgroupint intval($sbgroup); 
Once again the code will run fine it it is fed
PHP Code:
$userdata->fetch_field('membergroupids'
from useradmin_update_save which suggests that the problem is not in this part but in the sql of getting membergroupids directly from the database.

--------------- Added [DATE]1306036694[/DATE] at [TIME]1306036694[/TIME] ---------------

I have even tried:

Code:
$membergroupids = fetch_membergroupids_array($user, false);
still not working correctly... no errors I am making the changes directly in the function directly without using the hook to avoid any complications. I know the above function should be working as it is used as part of the default vb code within the same function.

but then doing:

PHP Code:
$sbusergroups $sbmemgroups;

foreach(
$sbusergroups as $sbgroup)
    {
        
$sbgroupint intval($sbgroup); 
does nothing

however from useradmin_update_save I can do:

PHP Code:
$sbmemgroups $userdata->fetch_field('membergroupids');

$sbusergroups explode(","$sbmemgroups);

foreach(
$sbusergroups as $sbgroup)
    {
        
$sbgroupint intval($sbgroup); 
and that works without any problem... all I want is to be able to get the member groups of the user in paidsub_build and process it though:
PHP Code:
foreach($sbusergroups as $sbgroup)
    {
        
$sbgroupint intval($sbgroup); 
just as I am able to do from useradmin_update_save

--------------- Added [DATE]1306050752[/DATE] at [TIME]1306050752[/TIME] ---------------

I think there may be a way to get the output I want via the fetch_membergroupids_array function but I do not know how to use it.

As stated above as long as I can get something that works as the below does but for paidsub_buid I am good:
PHP Code:
$sbmemgroups $userdata->fetch_field('membergroupids');

$sbusergroups explode(","$sbmemgroups);

foreach(
$sbusergroups as $sbgroup)
    {
        
$sbgroupint intval($sbgroup); 
--------------- Added [DATE]1306057439[/DATE] at [TIME]1306057439[/TIME] ---------------

Ok so here is what I did to test this out:

I fed the data directly from txt files so that I could see that the functions run correctly. The program grabs no data externally just runs identical code on the paidsub_build hook and the useradmin_update_save hook.

When run from the paidsub_build it never runs completely but useradmin_update_save works. They both use exactly the same code. Example:

PHP Code:
$sbmemgroups2 file_get_contents('data2.txt');
    
$sbusergroups explode(","$sbmemgroups2);

foreach(
$sbusergroups as $sbgroup)
    {
        
$sbgroupint intval($sbgroup);

if (
$sbgroupint == 16)
        {
            
$sbpaid true;
        }

The contents of data2.txt are not changed. When run via useradmin_update_save returns true and when run via paidsub_build returns false...
Reply With Quote
  #10  
Old 05-22-2011, 01:34 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is the code you posted the entire plugin? Are you sure the paidsub_build hook is even getting executed? Where are you checking the "returned" value?

The only thing I can think of from what you posted is that the paidsub_build hook is in a function and the other hook isn't, so if you're trying to set a global you probably need to add a "global $sbpaid;" line (or else set an existing global instead).

Also, sometimes you can debug by echoing an HTML comment, like

Code:
echo "<!-- sbusergroups = $sbusergroups -->\r\n"

then view the page source.
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:18 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.09514 seconds
  • Memory Usage 2,282KB
  • 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
  • (4)bbcode_code
  • (14)bbcode_php
  • (1)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
  • (1)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