View Full Version : Mysql to Array fail

05/02/2013, 10:32 AM
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");
sscanf(result, "p<|>is[40]i", car_id[count], name[count], price[count]);

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...

05/02/2013, 05:06 PM
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.