[HELP] Mysql - Retrieving a string & saving it to variable
#1

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

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);
Reply
#3

If your string is getting pulled from the databse, you should

pawn Код:
format(VehicleInfo[vehicleid][vOwner], 60, "%s", Field[10]);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)