[HELP] Mysql - Retrieving a string & saving it to variable - 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: [HELP] Mysql - Retrieving a string & saving it to variable (
/showthread.php?tid=132864)
[HELP] Mysql - Retrieving a string & saving it to variable -
viKKmaN - 09.03.2010
I have a problem with saving a string to a variable... keep getting diferent errors about array and stuff like that. If someone could tell me what i'm doing wrong...
Код:
stock LoadVehicles()
{
new query[128], Field[11][64], Row[128], vehicleid;
format(query, sizeof(query), "SELECT * FROM `vehicles`");
mysql_query(query);
mysql_store_result();
if(mysql_num_rows())
{
while(mysql_fetch_row_format(Row, ","))
{
split(Row, Field, ',');
mysql_free_result();
vehicleid = strval(Field[0]);
VehicleInfo[vehicleid][vModel] = strval(Field[1]);
VehicleInfo[vehicleid][vPosX] = strval(Field[2]);
VehicleInfo[vehicleid][vPosY] = strval(Field[3]);
VehicleInfo[vehicleid][vPosZ] = strval(Field[4]);
VehicleInfo[vehicleid][vPosA] = strval(Field[5]);
VehicleInfo[vehicleid][vColor1] = strval(Field[6]);
VehicleInfo[vehicleid][vColor2] = strval(Field[7]);
VehicleInfo[vehicleid][vBuyable] = strval(Field[8]);
VehicleInfo[vehicleid][vPrice] = strval(Field[9]);
VehicleInfo[vehicleid][vOwner] = Field[10];
printf("%i (%s) = CreateVehicle(%i, %f, %f, %f, %f, %i, %i, %i);", vehicleid, VehicleInfo[vehicleid][vOwner], VehicleInfo[vehicleid][vModel], VehicleInfo[vehicleid][vPosX], VehicleInfo[vehicleid][vPosY], VehicleInfo[vehicleid][vPosZ], VehicleInfo[vehicleid][vPosA], VehicleInfo[vehicleid][vColor1], VehicleInfo[vehicleid][vColor2], 60);
//CreateVehicle(VehicleInfo[vehicleid][vModel], VehicleInfo[vehicleid][vPosX], VehicleInfo[vehicleid][vPosY], VehicleInfo[vehicleid][vPosZ], VehicleInfo[vehicleid][vPosA], VehicleInfo[vehicleid][vColor1], VehicleInfo[vehicleid][vColor2], 60);
}
}
mysql_free_result();
}
My problem is with this line:
Код:
VehicleInfo[vehicleid][vOwner] = Field[10];
I know strval modifies the variable and returns an integer... but what function should i use to return a string... like strstr? which doesn't exist...
Re: [HELP] Mysql - Retrieving a string & saving it to variable -
Carlton - 09.03.2010
What's the point of
Код:
format(query, sizeof(query), "SELECT * FROM `vehicles`");
mysql_query(query);
?
Anyway, you should use strmid in a example like this:
Код:
strmid(VehicleInfo[vehicleid][vOwner], field[10], 0, strlen(field[10]), 255);
Re: [HELP] Mysql - Retrieving a string & saving it to variable -
Anwix - 09.03.2010
If your string is getting pulled from the databse, you should
pawn Код:
format(VehicleInfo[vehicleid][vOwner], 60, "%s", Field[10]);