Mysql to Array fail
#1

Код:
new car_id[20], name[20], price[20], result[200], count;
mysql_query("SELECT car_id, name, price FROM `cars` WHERE shop = '2' ORDER BY `price` ASC");
mysql_store_result();
while(mysql_fetch_row_format(result)){
	sscanf(result, "p<|>is[40]i", car_id[count], name[count], price[count]);
	count++;
}
mysql_free_result();
This sample works as it should and prints out "415 Cheetah 123485"
Код:
new test[100];
format(test,sizeof(test),"%d %s %d",car_id[0],name[0],price[0]);
SendClientMessage(playerid, GREEN, test);
However this sample somehow breaks and prints out "451 IISBBJPESATCheetah 123428".
It should print: "451 Turismo 123428"
Код:
new test2[100];
format(test,sizeof(test2),"%d %s %d",car_id[1],name[1],price[1]);
SendClientMessage(playerid, GREEN, test2);
Mysql fetch works good and everything breaks somewhere in sscanf's %s or format %s area.
Im in to pawn programming for about a week now and can't figure this out.
Im sure it's some silly mistake, please help me

Also it would be nice to know if anyone figured a way to fetch unknown number of mysql rows to array without specifying index(something like dynamic array).Maybe there's a workaround or something...
Reply
#2

Ye..well...it took some time but I figured out the problem myself...
It's just that strings are arrays themselfs (at least i think they are) and to define string as array(dont know how to call it here) you need to do something like that :
Код:
 new somestring[arrayindex][stringlength];
Close/Delete this thread.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)