SA-MP Forums Archive
Why it don't work? Load MYSQL - 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: Why it don't work? Load MYSQL (/showthread.php?tid=590291)



Why it don't work? Load MYSQL - maikons - 27.09.2015

I have a problem to load strings on mysql
All ints/floats are loading right, but strings can't load!! Why!? Any can help me to fix?

Код:
			cache_get_field_content(factionid, "facname", FactionInfo[factionid][facname]);
			cache_get_field_content(factionid, "lider1", FactionInfo[factionid][lider1]);
			cache_get_field_content(factionid, "lider2", FactionInfo[factionid][lider2]);
			cache_get_field_content(factionid, "lider3", FactionInfo[factionid][lider3]);
			cache_get_field_content(factionid, "membro1", FactionInfo[factionid][membro1]);
			cache_get_field_content(factionid, "membro2", FactionInfo[factionid][membro2]);
			cache_get_field_content(factionid, "membro3", FactionInfo[factionid][membro3]);
			cache_get_field_content(factionid, "membro4", FactionInfo[factionid][membro4]);
			cache_get_field_content(factionid, "membro5", FactionInfo[factionid][membro5]);
			cache_get_field_content(factionid, "membro6", FactionInfo[factionid][membro6]);
			cache_get_field_content(factionid, "membro7", FactionInfo[factionid][membro7]);
			cache_get_field_content(factionid, "membro8", FactionInfo[factionid][membro8]);
			cache_get_field_content(factionid, "membro9", FactionInfo[factionid][membro9]);
			cache_get_field_content(factionid, "membro10", FactionInfo[factionid][membro10]);
			cache_get_field_content(factionid, "membro11", FactionInfo[factionid][membro11]);
			cache_get_field_content(factionid, "membro12", FactionInfo[factionid][membro12]);
Код:
CarregarFactions() {
    for(new factionid; factionid < MAX_FACTIONS; factionid++)
    {
        new query[50]; // Nгo precisa ser enorme como vocк tinha colocado; Precisa apenas caber sua query dentro dela
        mysql_format(ConnectMYSQL, query, sizeof(query), "SELECT * FROM factions WHERE ID = %d", factionid);
        mysql_function_query(ConnectMYSQL, query, true, "Carregar_Factions","i",factionid);
    }
}

// A forward e a public coloca no final do GM
forward Carregar_Factions(factionid);
public Carregar_Factions(factionid) {
    new rows, fields;
    cache_get_data(rows, fields);
    if(rows)
    {
			new int_dest[15];
			int_dest[0] = cache_get_field_content_int(0, "hq");               				FactionInfo[factionid][hq] = int_dest[0];
			int_dest[1] = cache_get_field_content_int(0, "cofredinheiro");               	FactionInfo[factionid][cofredinheiro] = int_dest[1];
			int_dest[2] = cache_get_field_content_int(0, "cofresalario");               	FactionInfo[factionid][cofresalario] = int_dest[2];
			int_dest[3] = cache_get_field_content_int(0, "cofrematerial");               	FactionInfo[factionid][cofrematerial] = int_dest[3];
			int_dest[4] = cache_get_field_content_int(0, "cofremaconha");               	FactionInfo[factionid][cofremaconha] = int_dest[4];
			int_dest[5] = cache_get_field_content_int(0, "EagleSPAWNfac");               	FactionInfo[factionid][EagleSPAWNfac] = int_dest[5];
			int_dest[6] = cache_get_field_content_int(0, "shotgunSPAWNfac");               	FactionInfo[factionid][shotgunSPAWNfac] = int_dest[6];
			int_dest[7] = cache_get_field_content_int(0, "spazSPAWNfac");               	FactionInfo[factionid][spazSPAWNfac] = int_dest[7];
			int_dest[8] = cache_get_field_content_int(0, "mp5SPAWNfac");               		FactionInfo[factionid][mp5SPAWNfac] = int_dest[8];
			int_dest[9] = cache_get_field_content_int(0, "akSPAWNfac");               		FactionInfo[factionid][akSPAWNfac] = int_dest[9];
			int_dest[10] = cache_get_field_content_int(0, "akSPAWNfac");              	 	FactionInfo[factionid][akSPAWNfac] = int_dest[10];
			int_dest[11] = cache_get_field_content_int(0, "m4SPAWNfac");             	  	FactionInfo[factionid][m4SPAWNfac] = int_dest[11];
			int_dest[12] = cache_get_field_content_int(0, "rifleSPAWNfac");               	FactionInfo[factionid][rifleSPAWNfac] = int_dest[12];
			int_dest[13] = cache_get_field_content_int(0, "sniperSPAWNfac");               	FactionInfo[factionid][sniperSPAWNfac] = int_dest[13];
			int_dest[14] = cache_get_field_content_int(0, "meleeSPAWNfac");               	FactionInfo[factionid][meleeSPAWNfac] = int_dest[14];
				
			cache_get_field_content(factionid, "facname", FactionInfo[factionid][facname]);
			cache_get_field_content(factionid, "lider1", FactionInfo[factionid][lider1]);
			cache_get_field_content(factionid, "lider2", FactionInfo[factionid][lider2]);
			cache_get_field_content(factionid, "lider3", FactionInfo[factionid][lider3]);
			cache_get_field_content(factionid, "membro1", FactionInfo[factionid][membro1]);
			cache_get_field_content(factionid, "membro2", FactionInfo[factionid][membro2]);
			cache_get_field_content(factionid, "membro3", FactionInfo[factionid][membro3]);
			cache_get_field_content(factionid, "membro4", FactionInfo[factionid][membro4]);
			cache_get_field_content(factionid, "membro5", FactionInfo[factionid][membro5]);
			cache_get_field_content(factionid, "membro6", FactionInfo[factionid][membro6]);
			cache_get_field_content(factionid, "membro7", FactionInfo[factionid][membro7]);
			cache_get_field_content(factionid, "membro8", FactionInfo[factionid][membro8]);
			cache_get_field_content(factionid, "membro9", FactionInfo[factionid][membro9]);
			cache_get_field_content(factionid, "membro10", FactionInfo[factionid][membro10]);
			cache_get_field_content(factionid, "membro11", FactionInfo[factionid][membro11]);
			cache_get_field_content(factionid, "membro12", FactionInfo[factionid][membro12]);
			
			new Float:float_dest[4];
			float_dest[0] = cache_get_field_content_float(0, "HQposX");     	FactionInfo[factionid][HQposX] = float_dest[0];
			float_dest[1] = cache_get_field_content_float(0, "HQposY");     	FactionInfo[factionid][HQposY] = float_dest[1];
			float_dest[2] = cache_get_field_content_float(0, "HQposZ");     	FactionInfo[factionid][HQposZ] = float_dest[2];
    }
}



Re: Why it don't work? Load MYSQL - maikons - 28.09.2015

bump


Re: Why it don't work? Load MYSQL - PrO.GameR - 28.09.2015

Loading strings from mysql to enums requires you to insert the size manually
for example
PHP код:
            cache_get_field_content(factionid"facname"FactionInfo[factionid][facname]); 
should be
PHP код:
            cache_get_field_content(factionid"facname"FactionInfo[factionid][facname],1,30); 
where 30 is size of FactionInfo[factionid][facname], change these lines to the format I provided, change the size to right ones, and they will load correctly.


Re: Why it don't work? Load MYSQL - garotin - 28.09.2015

You need to set the size of your variable in cache_get_field_content.
example:
PHP код:
 cache_get_field_content (factionid"facname" FactionInfo [factionid] [facname], 1size here); 



Re: Why it don't work? Load MYSQL - maikons - 29.09.2015

I try put

my matrix
Код:
enum Factioninfos
{
    ID,
    facname[32],
	hq,
    Float:HQposX,
    Float:HQposY,
    Float:HQposZ,
	cofredinheiro,
	cofresalario,
	cofrematerial,
	cofremaconha,
	lider1[30],
	lider2[30],
	lider3[30],
	membro1[30],
	membro2[30],
	membro3[30],
	membro4[30],
	membro5[30],
	membro6[30],
	membro7[30],
	membro8[30],
	membro9[30],
	membro10[30],
	membro11[30],
	membro12[30],
	pistolSPAWNfac,
	shotgunSPAWNfac,
	submachineSPAWNfac,
	assaultSPAWNfac,
	sniperSPAWNfac,
    meleeSPAWNfac
}
new FactionInfo[MAX_FACTIONS][Factioninfos];
Код:
			cache_get_field_content(factionid, "facname", FactionInfo[factionid][facname],1,32);  
			cache_get_field_content(factionid, "lider1", FactionInfo[factionid][lider1],1,30); 
			cache_get_field_content(factionid, "lider2", FactionInfo[factionid][lider2],1,30); 
			cache_get_field_content(factionid, "lider3", FactionInfo[factionid][lider3],1,30); 
			cache_get_field_content(factionid, "membro1", FactionInfo[factionid][membro1],1,30); 
			cache_get_field_content(factionid, "membro2", FactionInfo[factionid][membro2],1,30); 
			cache_get_field_content(factionid, "membro3", FactionInfo[factionid][membro3],1,30); 
			cache_get_field_content(factionid, "membro4", FactionInfo[factionid][membro4],1,30); 
			cache_get_field_content(factionid, "membro5", FactionInfo[factionid][membro5],1,30); 
			cache_get_field_content(factionid, "membro6", FactionInfo[factionid][membro6],1,30); 
			cache_get_field_content(factionid, "membro7", FactionInfo[factionid][membro7],1,30); 
			cache_get_field_content(factionid, "membro8", FactionInfo[factionid][membro8],1,30); 
			cache_get_field_content(factionid, "membro9", FactionInfo[factionid][membro9],1,30); 
			cache_get_field_content(factionid, "membro10", FactionInfo[factionid][membro10],1,30); 
			cache_get_field_content(factionid, "membro11", FactionInfo[factionid][membro11],1,30); 
			cache_get_field_content(factionid, "membro12", FactionInfo[factionid][membro12],1,30);
And try
Код:
			cache_get_field_content(factionid, "facname", FactionInfo[factionid][facname],ConnectMYSQL,32);  
			cache_get_field_content(factionid, "lider1", FactionInfo[factionid][lider1],ConnectMYSQL,30); 
			cache_get_field_content(factionid, "lider2", FactionInfo[factionid][lider2],ConnectMYSQL,30); 
			cache_get_field_content(factionid, "lider3", FactionInfo[factionid][lider3],ConnectMYSQL,30); 
			cache_get_field_content(factionid, "membro1", FactionInfo[factionid][membro1],ConnectMYSQL,30); 
			cache_get_field_content(factionid, "membro2", FactionInfo[factionid][membro2],ConnectMYSQL,30); 
			cache_get_field_content(factionid, "membro3", FactionInfo[factionid][membro3],ConnectMYSQL,30); 
			cache_get_field_content(factionid, "membro4", FactionInfo[factionid][membro4],ConnectMYSQL,30); 
			cache_get_field_content(factionid, "membro5", FactionInfo[factionid][membro5],ConnectMYSQL,30); 
			cache_get_field_content(factionid, "membro6", FactionInfo[factionid][membro6],ConnectMYSQL,30); 
			cache_get_field_content(factionid, "membro7", FactionInfo[factionid][membro7],ConnectMYSQL,30); 
			cache_get_field_content(factionid, "membro8", FactionInfo[factionid][membro8],ConnectMYSQL,30); 
			cache_get_field_content(factionid, "membro9", FactionInfo[factionid][membro9],ConnectMYSQL,30); 
			cache_get_field_content(factionid, "membro10", FactionInfo[factionid][membro10],ConnectMYSQL,30); 
			cache_get_field_content(factionid, "membro11", FactionInfo[factionid][membro11],ConnectMYSQL,30); 
			cache_get_field_content(factionid, "membro12", FactionInfo[factionid][membro12],ConnectMYSQL,30);
When load, don't load correcty valor...

Load: NULL



Re: Why it don't work? Load MYSQL - maikons - 30.09.2015

My save system is working fine i think
Код:
stock SalvarFactions()
{
	for(new factionid; factionid < MAX_FACTIONS; factionid++) {
        new query[1030];
        format(query, sizeof(query), "UPDATE `factions` SET `facname` = '%s', `HQposX` = '%f', `HQposY` = '%f', `HQposZ` = '%f', `pistolSPAWNfac` = '%d', `shotgunSPAWNfac` = '%d', `submachineSPAWNfac` = '%d', `assaultSPAWNfac` = '%d', `sniperSPAWNfac` = '%d', `meleeSPAWNfac` = '%d', `cofredinheiro` = '%d', `cofresalario` = '%d', `cofrematerial` = '%d', `cofremaconha` = '%d' WHERE `ID` = '%i' ",
            FactionInfo[factionid][facname],
            FactionInfo[factionid][HQposX],
            FactionInfo[factionid][HQposY],
            FactionInfo[factionid][HQposZ],
            FactionInfo[factionid][pistolSPAWNfac],
            FactionInfo[factionid][shotgunSPAWNfac],
            FactionInfo[factionid][submachineSPAWNfac],
            FactionInfo[factionid][assaultSPAWNfac],
            FactionInfo[factionid][sniperSPAWNfac],
            FactionInfo[factionid][meleeSPAWNfac],
            FactionInfo[factionid][cofredinheiro],
            FactionInfo[factionid][cofresalario],
            FactionInfo[factionid][cofrematerial],
            FactionInfo[factionid][cofremaconha],
            factionid);
        mysql_pquery(ConnectMYSQL, query);

        format(query, sizeof(query), "UPDATE `factions` SET `lider1` = '%s', `lider2` = '%s', `lider3` = '%s', `membro1` = '%s', `membro2` = '%s', `membro3` = '%s', `membro4` = '%s', `membro5` = '%s', `membro6` = '%s', `membro7` = '%s', `membro8` = '%s', `membro9` = '%s', `membro10` = '%s', `membro11` = '%s', `membro12` = '%s' WHERE `ID` = '%i' ",
            FactionInfo[factionid][lider1],
            FactionInfo[factionid][lider2],
            FactionInfo[factionid][lider3],
            FactionInfo[factionid][membro1],
            FactionInfo[factionid][membro2],
            FactionInfo[factionid][membro3],
            FactionInfo[factionid][membro4],
            FactionInfo[factionid][membro5],
            FactionInfo[factionid][membro6],
            FactionInfo[factionid][membro7],
            FactionInfo[factionid][membro8],
            FactionInfo[factionid][membro9],
            FactionInfo[factionid][membro10],
            FactionInfo[factionid][membro11],
            FactionInfo[factionid][membro12],
            factionid);
        mysql_pquery(ConnectMYSQL, query);
	}
	return 1;
}



Re: Why it don't work? Load MYSQL - garotin - 30.09.2015

Show me CarregarFactions()


Re: Why it don't work? Load MYSQL - PrO.GameR - 30.09.2015

It's because when you select rows in mysql, row number starts from 0 (and usually there is only 1 row unless you have duplicate factions) so
PHP код:
cache_get_field_content(0"facname"FactionInfo[factionid][facname],1,32); 
sry didn't notice it the first time, change all those factionid to 0 and it will load perfectly.