how to get all vehicles from mysql... -
Sascha - 17.02.2011
I'm using mysql as my vehicle database and I want to spawn all vehicles in it and I actually also know how it works...
but now I have the problem to read from the different vehicle rows...
I've got this:
pawn Код:
new query[50], tmp[256];
format(query, sizeof(query), "SELECT * FROM `Vehicles`");
mysql_query(query);
mysql_store_result();
for(new v=0; v<mysql_num_rows(); v++)
{
mysql_fetch_field("model", tmp);
VehicleData[v][model] = strval(tmp);
mysql_fetch_field("xpos", tmp);
VehicleData[v][xpos] = floatstr(tmp);
mysql_fetch_field("ypos", tmp);
VehicleData[v][ypos] = floatstr(tmp);
mysql_fetch_field("zpos", tmp);
VehicleData[v][zpos] = floatstr(tmp);
mysql_fetch_field("apos", tmp);
VehicleData[v][apos] = floatstr(tmp);
mysql_fetch_field("color1", tmp);
VehicleData[v][c1] = strval(tmp);
mysql_fetch_field("color2", tmp);
VehicleData[v][c2] = strval(tmp);
mysql_fetch_field("interior", tmp);
VehicleData[v][interior] = strval(tmp);
CreateVehicle(VehicleData[v][model], VehicleData[v][xpos], VehicleData[v][ypos], VehicleData[v][zpos], VehicleData[v][apos], VehicleData[v][c1], VehicleData[v][c2], 300);
LinkVehicleToInterior(v, VehicleData[v][interior]);
if(!strcmp(VehicleData[v][plate], "none", true))
{
}else{
SetVehicleNumberPlate(v, VehicleData[v][plate]);
}
}
mysql_free_result();
however it ofc always gets the information of the first row and spawns it 4 times (currently 4 vehicles in the db)...
so how can I differ between the rows?
Re: how to get all vehicles from mysql... -
Blacklite - 17.02.2011
Use something like this instead of the loop you have at the moment:
pawn Код:
for(new v=0; v<mysql_num_rows() && mysql_fetch_row(); v++)
Not sure of the correct syntax for your mysql_fetch_row, you'll have to look it up (it may depend on your plugin).
Basically, you need to be fetching a new row each time the loop goes through, and mysql_fetch_row will move to the next row.
Re: how to get all vehicles from mysql... -
Sascha - 18.02.2011
" warning 202: number of arguments does not match definition"
in the loop line...
(I'm using stricken's mysql plugin)
with thise code
pawn Код:
for(new v=0; v<mysql_num_rows() && mysql_fetch_row(); v++)
I looked at wiki but somehow I didn't get the right syntax
if I use "mysql_fetch_row(v)" I get "error 035: argument type mismatch (argument 1)"
Re: how to get all vehicles from mysql... -
Criss_Angel - 18.02.2011
try
pawn Код:
new here;
for(new v=0; v<mysql_num_rows(); v++)
{
here++;
mysql_fetch_row(here);
}
Re: how to get all vehicles from mysql... -
Sascha - 18.02.2011
error 035: argument type mismatch (argument 1)
Re: how to get all vehicles from mysql... -
Sascha - 19.02.2011
bump
Re: how to get all vehicles from mysql... -
Blacklite - 21.02.2011
use mysql_fetch_row like:
pawn Код:
new row[64];
for(new v=0; mysql_fetch_row(row, "|"); v++) {
// mysql_fetch_field etc
}