SA-MP Forums Archive
Problem with Loading Stuff from 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem with Loading Stuff from Mysql (/showthread.php?tid=79935)



Problem with Loading Stuff from Mysql - Doktor - 31.05.2009

Hi, i have some Problems with Loading some Stuff from Mysql. The Code looks like this:
Код:
for (new b = 1; b <= gBuilding; b++)
	{
   	format(sql, sizeof(sql), "SELECT * FROM building WHERE id='%d'", b);
	  samp_mysql_query(sql);
	  samp_mysql_store_result();
	  if (samp_mysql_num_rows() > 0)
	  {
			samp_mysql_fetch_row(Data);
			printf("%s",Data);
			if(sscanf(Data,"p|dffffffdsd",
			b,
			BuildingInfo[b][buEntrancex],
			BuildingInfo[b][buEntrancey],
			BuildingInfo[b][buEntrancez],
			BuildingInfo[b][buExitx],
			BuildingInfo[b][buExity],
			BuildingInfo[b][buExitz],
			BuildingInfo[b][buInterior],
			BuildingInfo[b][buMessage],
			BuildingInfo[b][buCost])) printf("Fail");
			printf("%d %f %f %f",b,BuildingInfo[b][buEntrancex],BuildingInfo[b][buEntrancey],BuildingInfo[b][buEntrancez]);
			
		}
	}
The Output in my Log looks like
Код:
1|-1422.358765|-288.384186|14.148400|0.000000|0.000000|0.000000|0|Aiport|0
1 0.000000 0.000000 0.000000
2|-2026.781128|-100.340599|35.164101|2026.790527|-104.883400|1035.171875|3|Driving School|5000
2 0.000000 0.000000 0.000000
So whats wrong? Why doesnt it work properly?





Re: Problem with Loading Stuff from Mysql - Doktor - 01.06.2009

I tried the same with my players row
Код:
format(string, sizeof(string), "SELECT Password, Admin, Gun1, Ammo1 FROM players WHERE id = '%d' LIMIT 1", PlayerInfo[playerid][pID]);
	samp_mysql_query(string);
	samp_mysql_store_result();
	samp_mysql_fetch_row(Data);
	if(sscanf(Data,"p|sddd",
	PlayerInfo[playerid][pPassword],
	PlayerInfo[playerid][pAdmin],
	PlayerInfo[playerid][pGun1],
	PlayerInfo[playerid][pAmmo1]
	)) print("Fail");
And it works. Why does the same thing doesnt work with my other table in mysql? Could someone please help me, i really need to get it working.


Re: Problem with Loading Stuff from Mysql - MenaceX^ - 01.06.2009

Why do you split it by using sscanf?
Though it's kindda useless:
pawn Код:
format(sql, sizeof(sql), "SELECT * FROM building WHERE id='%d'", b);
samp_mysql_query(sql);
Because in your loop you just select everything, you can do instead
pawn Код:
samp_mysq_query("SELECT * FROM `building`");



Re: Problem with Loading Stuff from Mysql - Doktor - 01.06.2009

Thanks for your answear, im using sscanf because im used to it (dcmd + sscanf), so i thought i could use it this way here, which only works for players. I know theres also the "split" function (works, but i dont like this way) and samp_mysql_strtok (which doesnt work for me either). Whats the best and most effectiv way to split a mysql string? (split, sscanf or samp_mysql_strtok, what else?)

Код:
Because in your loop you just select everything, you can do instead
PAWN Code:

samp_mysq_query("SELECT * FROM `building`");
How would the rest of the Code will look like, if i do it how you described?

I need to split a mysql string for building (small table - see above), players (big table), factions, bizz and houses (medium table) and i would prefer using one method to split them all. I would use your method MenaceX, but im not sure what you mean with your code.


EDIT: Nothing important, but sscanf has problems with splitting the floats in my building table, the strings and integers work.



Re: Problem with Loading Stuff from Mysql - Doktor - 01.06.2009

I tried it using the split Function and it works, but whats the best way and most effectiv way to split such strings?



Re: Problem with Loading Stuff from Mysql - Ignas1337 - 01.06.2009

why don't you like split?


Re: Problem with Loading Stuff from Mysql - Doktor - 01.06.2009

Because it doesnt work with large strings. I used it with my "players" table and it just stopped and returned "Unknown Command" on /login. So ill had to use 2 smaller querys to get it working.
Is split the best way to spit strings? Or is there any other better way?