Problem with Loading Stuff from Mysql
#1

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?


Reply
#2

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.
Reply
#3

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`");
Reply
#4

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.
Reply
#5

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

why don't you like split?
Reply
#7

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?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)