SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 22/07/2017, 03:14 PM   #1
Lirbo
Gangsta
 
Lirbo's Avatar
 
Join Date: Jan 2014
Posts: 504
Reputation: 8
Default [MySQL] tquery issue

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:

Last edited by Lirbo; 22/07/2017 at 04:10 PM.
Lirbo is offline   Reply With Quote
Old 22/07/2017, 03:18 PM   #2
Jefff
Banned
 
Join Date: Dec 2007
Posts: 2,593
Reputation: 326
Default Re: [MySQL] tquery issue

because you are getting all time row id 0 in cache_get_field
Jefff is offline   Reply With Quote
Old 22/07/2017, 04:10 PM   #3
Lirbo
Gangsta
 
Lirbo's Avatar
 
Join Date: Jan 2014
Posts: 504
Reputation: 8
Default Re: [MySQL] tquery issue

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
Lirbo is offline   Reply With Quote
Old 22/07/2017, 04:29 PM   #4
Kaperstone
Banned
 
Join Date: May 2011
Location: Russia
Posts: 3,004
Reputation: 824
Default Re: [MySQL] tquery issue

You have data, you know how it looks like,
think logically how you can solve the problem, you're a scripter
Kaperstone is offline   Reply With Quote
Old 22/07/2017, 04:56 PM   #5
Lirbo
Gangsta
 
Lirbo's Avatar
 
Join Date: Jan 2014
Posts: 504
Reputation: 8
Default Re: [MySQL] tquery issue

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
Lirbo is offline   Reply With Quote
Old 22/07/2017, 05:10 PM   #6
skuller12
Big Clucker
 
Join Date: Feb 2015
Location: Galati, Romania
Posts: 101
Reputation: 0
Default Re: [MySQL] tquery issue

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
skuller12 is offline   Reply With Quote
Old 22/07/2017, 05:20 PM   #7
Kaperstone
Banned
 
Join Date: May 2011
Location: Russia
Posts: 3,004
Reputation: 824
Default Re: [MySQL] tquery issue

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];
}
Kaperstone is offline   Reply With Quote
Old 22/07/2017, 07:20 PM   #8
Lirbo
Gangsta
 
Lirbo's Avatar
 
Join Date: Jan 2014
Posts: 504
Reputation: 8
Default Re: [MySQL] tquery issue

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!
Lirbo is offline   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


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL tquery Gotham Scripting Help 4 02/10/2016 12:27 PM
mysql tquery MartinSwag Scripting Help 3 23/08/2015 09:00 AM
MySQL question tquery Dan. Scripting Help 2 08/07/2015 02:35 PM
Mysql tquery/pquery Banditukas Scripting Help 3 21/08/2014 03:23 PM
Mysql tquery loop only loading once Jack_Leslie Scripting Help 6 07/07/2014 09:17 AM


All times are GMT. The time now is 10:41 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.