Raised This Month: $ Target: $400
 0% 

loop sql select


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
krisztian2
Junior Member
Join Date: Feb 2019
Old 06-30-2020 , 11:29   loop sql select
Reply With Quote #1

Hi guys!

I have a problem with sql loop. I want to SUM F0,F1,F2,F3,F4 column values and copy the results to
DB_skins array. So the code is:
PHP Code:
new szQuery[2048];
    new 
len 0;
    new 
szData[2];
    
szData[0] = id;
    
szData[1] = get_user_userid(id);
        
//This is the problem
    
for(new i=0<= 4;i++)
    {
    
len += format(szQuery[len], 2048"SELECT SUM(F%i) as F%i FROM accounts; ",i,i);
}
    
SQL_ThreadQuery(g_SqlTuple,"sql_piece_of_skins_thread"szQueryszData2);

public 
sql_piece_of_skins_thread(FailState,Handle:Query,Error[],Errcode,szData[],DataSize)
{
    if(
FailState == TQUERY_CONNECT_FAILED)
    {
        
set_fail_state("[ *ERROR* ] YOU CANNOT CONNECT TO THE DATABASE!");
        return;
    }
    else if(
FailState == TQUERY_QUERY_FAILED)
    {
        
set_fail_state("[ *ERROR* ] QUERY PROBLEM.");
        return;
    }
    
    if(
Errcode)
    {
        
log_amx("[ *ERROR* ] QUERY ERROR ( %s )",Error);
        return;
    }
    
    new 
id szData[0];
    
    if (
szData[1] != get_user_userid(id))
        return;
    
        for(new 
i=0;<= 4;i++)
        {
        
DB_skins[i][id] = SQL_ReadResult(Queryi);
        }
    
inventory(id);
    

Error is:
Code:
L 06/30/2020 - 17:07:21: [MySQL] Invalid column: 1
L 06/30/2020 - 17:07:21: [AMXX] Displaying debug trace (plugin "plugin.amxx")
L 06/30/2020 - 17:07:21: [AMXX] Run time error 10: native error (native "SQL_ReadResult")
krisztian2 is offline
 



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 -4. The time now is 17:06.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode