vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   [SOLVED] SQL Help (https://vborg.vbsupport.ru/showthread.php?t=263992)

ZERO <ibis> 05-22-2011 12:06 AM

[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 ;)

kh99 05-22-2011 12:10 AM

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".

ZERO <ibis> 05-22-2011 12:21 AM

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

kh99 05-22-2011 12:23 AM

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

ZERO <ibis> 05-22-2011 12:27 AM

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.

kh99 05-22-2011 12:28 AM

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


ZERO <ibis> 05-22-2011 12:32 AM

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']; 


kh99 05-22-2011 12:35 AM

Quote:

Originally Posted by ZERO <ibis> (Post 2198547)
For reference the following query runs fine:

OK, sorry, I guess i was wrong about what the problem was. Anyone else?

ZERO <ibis> 05-22-2011 12:40 AM

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... :eek:

kh99 05-22-2011 01:34 PM

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.


All times are GMT. The time now is 03:04 AM.

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.01161 seconds
  • Memory Usage 1,783KB
  • 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
  • (4)bbcode_code_printable
  • (14)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)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