SA-MP Forums Archive
[MySQL] tquery issue - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [MySQL] tquery issue (/showthread.php?tid=637845)



[MySQL] tquery issue - Lirbo - 22.07.2017

solved but another issue popped, check my comment
code:
PHP Code:
stock LoadClans()
{
    
mysql_tquery(sql"SELECT * FROM `clans`""tLoadClans");
    return 
1;
}
forward tLoadClans();
public 
tLoadClans()
{
    new 
rowsfields;
    
cache_get_data(rowsfields);
    if(
rows)
    {
        for(new 
0rowsi++)
        {
            
ClanDB[i][ClanID] = cache_get_field_content_int(0"clanid");
            
cache_get_field_content(0"clan_name"ClanDB[i][ClanName]);
            
ClanDB[i][ClanLevel] = cache_get_field_content_int(0"clan_level");
            
ClanDB[i][ClanEXP] = cache_get_field_content_int(0"clan_exp");
            
ClanDB[i][ClanMaxEXP] = cache_get_field_content_int(0"clan_max_exp");
            
ClanDB[i][ClanColor] = cache_get_field_content_int(0"clan_color");
            new 
str[32];
            
format(strsizeof(str), "ca %d"ClanDB[i][ClanMaxEXP]);
            
printf(str);
        }
    }

batch:
PHP Code:
ca 0
ca 0 
MySQL:



Re: [MySQL] tquery issue - Jefff - 22.07.2017

because you are getting all time row id 0 in cache_get_field


Re: [MySQL] tquery issue - Lirbo - 22.07.2017

Quote:
Originally Posted by Jefff
View Post
because you are getting all time row id 0 in cache_get_field
thanks worked, but now I have 1 more problem

PHP Code:
forward tLoadClans();
public 
tLoadClans()
{
    new 
rowsfieldsstr[128];
    
cache_get_data(rowsfields);
    if(
rows)
    {
        for(new 
0rowsi++)
        {
                
ClanDB[i][ClanID] = cache_get_field_content_int(i"clanid");
                
cache_get_field_content(i"clan_name"ClanDB[i][ClanName]);
                
ClanDB[i][ClanLevel] = cache_get_field_content_int(i"clan_level");
                
ClanDB[i][ClanEXP] = cache_get_field_content_int(i"clan_exp");
                
ClanDB[i][ClanMaxEXP] = cache_get_field_content_int(i"clan_max_exp");
                
ClanDB[i][ClanColor] = cache_get_field_content_int(i"clan_color");
                
format(strsizeof(str), "[%d] clanid: %d, exp: %d, max exp: %d",iClanDB[i][ClanID], ClanDB[i][ClanEXP], ClanDB[i][ClanMaxEXP]);
                
printf(str);
        }
    }

PHP Code:
[0clanid1exp0max exp0
[1clanid7exp 0max exp300 
the problem is that [0] = clanid 1 and [1] = clanid 7
I want the 'i' to be the clanid


Re: [MySQL] tquery issue - Kaperstone - 22.07.2017

You have data, you know how it looks like,
think logically how you can solve the problem, you're a scripter


Re: [MySQL] tquery issue - Lirbo - 22.07.2017

Quote:
Originally Posted by Kaperstone
View Post
You have data, you know how it looks like,
think logically how you can solve the problem, you're a scripter
Method 1:
PHP Code:
ClanDB[i][ClanID] = cache_get_field_content_int(ClanDB[i][ClanID], "clanid");
                
cache_get_field_content(ClanDB[i][ClanID], "clan_name"ClanDB[i][ClanName]);
                
ClanDB[i][ClanLevel] = cache_get_field_content_int(ClanDB[i][ClanID], "clan_level");
                
ClanDB[i][ClanEXP] = cache_get_field_content_int(ClanDB[i][ClanID], "clan_exp");
                
ClanDB[i][ClanMaxEXP] = cache_get_field_content_int(ClanDB[i][ClanID], "clan_max_exp");
                
ClanDB[i][ClanColor] = cache_get_field_content_int(ClanDB[i][ClanID], "clan_color");
format(strsizeof(str), "[%d] clanid: %d, exp: %d, max exp: %d",iClanDB[i][ClanID], ClanDB[i][ClanEXP], ClanDB[i][ClanMaxEXP]);
                
printf(str); 
PHP Code:
[0clanid1exp0max exp300
[1clanid1exp0max exp300 
Method 2:
PHP Code:
ClanDB[i][ClanID] = cache_get_field_content_int(i"clanid");
                
cache_get_field_content(i"clan_name"ClanDB[ClanDB[i][ClanID]][ClanName]);
                
ClanDB[ClanDB[i][ClanID]][ClanLevel] = cache_get_field_content_int(i"clan_level");
                
ClanDB[ClanDB[i][ClanID]][ClanEXP] = cache_get_field_content_int(i"clan_exp");
                
ClanDB[ClanDB[i][ClanID]][ClanMaxEXP] = cache_get_field_content_int(i"clan_max_exp");
                
ClanDB[ClanDB[i][ClanID]][ClanColor] = cache_get_field_content_int(i"clan_color");
                
format(strsizeof(str), "[%d] clanid: %d, exp: %d, max exp: %d",iClanDB[i][ClanID], ClanDB[i][ClanEXP], ClanDB[i][ClanMaxEXP]);
                
printf(str); 
PHP Code:
[0clanid1exp0max exp0
[1clanid7exp0max exp
i'd be more than happy if you can assist me, i'll try to make more changes meanwhile to try to solve


Re: [MySQL] tquery issue - skuller12 - 22.07.2017

mysql_tquery(sql, "SELECT * FROM `clans`", "tLoadClans", "");

Edit:

new id;

id = cache_get_field_content_int(i, "clanID");
and

ClanDB[id][ClanID] = cache_get_field_content_int(i, "clanid");
cache_get_field_content(i, "clan_name", ClanDB[id][ClanName]);
etc


Re: [MySQL] tquery issue - Kaperstone - 22.07.2017

How about simple solution such as temporary holder ?
create a new array with roughly the same size as ClanDB, insert data into it and then create another loop where you switch data between them like so
pawn Code:
new fixer[][];

for(new i=0;i<rows;i++) {fixer=mysql}

for(new i=0;i<rows;i++) {
    ClanDB[fixer[i][ClanID]][name]=fixer[i][name];
}



Re: [MySQL] tquery issue - Lirbo - 22.07.2017

Quote:
Originally Posted by Kaperstone
View Post
How about simple solution such as temporary holder ?
create a new array with roughly the same size as ClanDB, insert data into it and then create another loop where you switch data between them like so
pawn Code:
new fixer[][];

for(new i=0;i<rows;i++) {fixer=mysql}

for(new i=0;i<rows;i++) {
    ClanDB[fixer[i][ClanID]][name]=fixer[i][name];
}
Thank you so much bro!