Raised This Month: $32 Target: $400
 8% 

loop sql select


Post New Thread Reply   
 
Thread Tools Display Modes
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
spamipolito
Junior Member
Join Date: Jun 2018
Old 07-01-2020 , 15:17   Re: loop sql select
Reply With Quote #2

PHP Code:

#define MAX_SKINS 4

public LoadSkins(const id)
{
    static 
szQuery[256], szData[1]

    new 
iLen 0;

    
iLen += formatexszQueryiLen ], charsmaxszQuery ) - iLen"SELECT ")

    for(new 
i=0<= MAX_SKINS;i++)
        
iLen += formatexszQueryiLen ], charsmaxszQuery ) - iLen"`F%d`%s "i== MAX_SKINS "" ",")

    
iLen += formatexszQueryiLen ], charsmaxszQuery ) - iLen"FROM `accounts` WHERE `PlayerID`='%d'"get_user_authid(id) )

    
szData[0] = id;

    
SQL_ThreadQuery(g_SqlTuple,"sql_piece_of_skins_thread"szQueryszData1);
}

public 
sql_piece_of_skins_thread(FailState,Handle:Query,Error[],Errcode,szData[],DataSize)
{
    if(
iFailState == TQUERY_CONNECT_FAILED || iFailState == TQUERY_QUERY_FAILED
    { 
        
log_amx("%s"szError)
        return
    } 
    else 
    {
        new 
id iData[0]

        for(new 
i=0;<= MAX_SKINS;i++)
            
DB_skins[i][id] = SQL_ReadResult(Query/*Colum Num*/);
            
        
inventory(id);
    } 
}


public 
TestConsult(const id)
{
    
// Use register_clcmd to testing consult. Return console print
    
new iLen 0
    
new szQuery[256]

    
iLen += formatexszQueryiLen ], charsmaxszQuery ) - iLen"SELECT ")

    for(new 
i=0<= MAX_SKINS;i++)
        
iLen += formatexszQueryiLen ], charsmaxszQuery ) - iLen"`F%d`%s "i== MAX_SKINS "" ",")

    
iLen += formatexszQueryiLen ], charsmaxszQuery ) - iLen"FROM `accounts` WHERE `PlayerID`='%d'")

    
console_print(id"%s"szQuery)


Share the structure of the database "accounts"

Last edited by spamipolito; 07-01-2020 at 15:33.
spamipolito is offline
krisztian2
Junior Member
Join Date: Feb 2019
Old 07-04-2020 , 17:14   Re: loop sql select
Reply With Quote #3

Thank you for your reply, but i want to sum F0, F1.. F4 columns of players. And the results save to an array.
krisztian2 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-04-2020 , 18:26   Re: loop sql select
Reply With Quote #4

Use flags instead of strings for saving.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 07-04-2020 at 18:26.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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 -4. The time now is 03:28.


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