MySQL not loading vehicles -
CONTROLA - 08.08.2011
pawn Код:
for(new ca = 0; ca < 200; ca++)
{
new data[256], query[512], string[256];
new aux[50][12];
format(query, sizeof(query), "SELECT * FROM `vehicles` WHERE CarID = %d",ca);
mysql_query(query);
mysql_store_result();
printf("step1");
//if(mysql_num_rows() > 0)
//{
//if(strmatch(VehicleSystem[h][Owner],"Unbought")) return 1;
Globalcarid++;
mysql_fetch_row_format(data);
splitGF(data, aux, '|');
VehicleSystem[ca][CarID]=strval(aux[0]);
printf("lalala");
VehicleSystem[ca][Model]=strval(aux[1]);
VehicleSystem[ca][Locked]=strval(aux[2]);
VehicleSystem[ca][Carx]=floatstr(aux[3]);
VehicleSystem[ca][Cary]=floatstr(aux[4]);
VehicleSystem[ca][Carz]=floatstr(aux[5]);
VehicleSystem[ca][Cara]=floatstr(aux[6]);
VehicleSystem[ca][Color1]=strval(aux[7]);
VehicleSystem[ca][Color2]=strval(aux[8]);
VehicleSystem[ca][Price]=strval(aux[9]);
VehicleSystem[ca][Sell]=strval(aux[10]);
format(string, sizeof(string), "%s loaded", ca);
printf(string);
strmid(VehicleSystem[ca][Owner],aux[11],0,20,20);
//VehicleSystem[ca][Owner] = aux[11];
new carr = CreateVehicle(VehicleSystem[ca][Model],VehicleSystem[ca][Carx],VehicleSystem[ca][Cary],VehicleSystem[ca][Carz]+5,VehicleSystem[ca][Cara],VehicleSystem[ca][Color1],VehicleSystem[ca][Color2],600000);
IsBuyableCar[carr]=ca;
printf("step3");
SaveMYSQLCarID(carr);
printf("step4");
//}
}
Does anyone know what's the problem? The vehicles just don't load and the database has vehicles in it.
Re: MySQL not loading vehicles -
Calgon - 08.08.2011
You need to be more specific. Which plugin are you using for MySQL? Have you tried to do more to debug this problem?
Re: MySQL not loading vehicles -
CONTROLA - 08.08.2011
I'm using MySQL R6 by G-Stylez.
Re: MySQL not loading vehicles -
Calgon - 08.08.2011
First of all, you should understand that looping a query is pretty stupid. You should create the query and then use a while loop to retrieve each row, with some form of iterator integer to sort the data in to an array.
Secondly, you need to retrieve the row before trying to use data from it, use the function mysql_retrieve_row() after storing the result.
Re: MySQL not loading vehicles -
CONTROLA - 08.08.2011
Can you please edit my code? I've tried but I can't do it right.
Re: MySQL not loading vehicles -
Calgon - 08.08.2011
pawn Код:
for(new ca = 0; ca < 200; ca++)
{
new data[256], query[512], string[256];
new aux[50][12];
format(query, sizeof(query), "SELECT * FROM `vehicles` WHERE CarID = %d",ca);
mysql_query(query);
mysql_store_result();
printf("step1");
mysql_retrieve_row(); // Changed line
//if(mysql_num_rows() > 0)
//{
//if(strmatch(VehicleSystem[h][Owner],"Unbought")) return 1;
Globalcarid++;
mysql_fetch_row_format(data);
splitGF(data, aux, '|');
VehicleSystem[ca][CarID]=strval(aux[0]);
printf("lalala");
VehicleSystem[ca][Model]=strval(aux[1]);
VehicleSystem[ca][Locked]=strval(aux[2]);
VehicleSystem[ca][Carx]=floatstr(aux[3]);
VehicleSystem[ca][Cary]=floatstr(aux[4]);
VehicleSystem[ca][Carz]=floatstr(aux[5]);
VehicleSystem[ca][Cara]=floatstr(aux[6]);
VehicleSystem[ca][Color1]=strval(aux[7]);
VehicleSystem[ca][Color2]=strval(aux[8]);
VehicleSystem[ca][Price]=strval(aux[9]);
VehicleSystem[ca][Sell]=strval(aux[10]);
format(string, sizeof(string), "%s loaded", ca);
printf(string);
strmid(VehicleSystem[ca][Owner],aux[11],0,20,20);
//VehicleSystem[ca][Owner] = aux[11];
new carr = CreateVehicle(VehicleSystem[ca][Model],VehicleSystem[ca][Carx],VehicleSystem[ca][Cary],VehicleSystem[ca][Carz]+5,VehicleSystem[ca][Cara],VehicleSystem[ca][Color1],VehicleSystem[ca][Color2],600000);
IsBuyableCar[carr]=ca;
printf("step3");
SaveMYSQLCarID(carr);
printf("step4");
//}
}
Re: MySQL not loading vehicles -
Donya - 08.08.2011
my vehicle system is actually based off of this one too. - Calg00ne beat me.. but mine will use less memory/faster ^^
pawn Код:
stock LoadVehicles()
{
new result[24], index = 0;
mysql_query("SELECT * FROM `vehicles` ORDER BY `vehicles`.`CarID` ASC");
mysql_store_result();
while(mysql_retrieve_row())
{
index++;
mysql_get_field("CarID", result);
VehicleSystem[index][CarID] = strval(result);
mysql_get_field("Model", result);
VehicleSystem[index][Model] = strval(result);
mysql_get_field("Locked", result);
VehicleSystem[index][Locked] = strval(result);
mysql_get_field("CarX", result);
VehicleSystem[index][Carx] = floatstr(result);
mysql_get_field("CarY", result);
VehicleSystem[index][Cary] = floatstr(result);
mysql_get_field("CarZ", result);
VehicleSystem[index][Carz] = floatstr(result);
mysql_get_field("CarA", result);
VehicleSystem[index][Cara] = floatstr(result);
mysql_get_field("Color1", result);
VehicleSystem[index][Color1] = strval(result);
mysql_get_field("Color2", result);
VehicleSystem[index][Color2] = strval(result);
mysql_get_field("Price", result);
VehicleSystem[index][Price] = strval(result);
mysql_get_field("Sell", result);
VehicleSystem[index][Sell] = strval(result);
mysql_get_field("Owner", result);
printf("%s loaded", result);
strmid(VehicleSystem[index][Owner], result, false, strlen(result), 24);
new carr = CreateVehicle(VehicleSystem[index][Model],VehicleSystem[index][Carx],VehicleSystem[index][Cary],VehicleSystem[index][Carz]+5,VehicleSystem[index][Cara],VehicleSystem[index][Color1],VehicleSystem[index][Color2],600000);
IsBuyableCar[carr]=index;
//SaveMYSQLCarID(carr);
Globalcarid++;
}
mysql_free_result();
return 1;
}
Re: MySQL not loading vehicles -
CONTROLA - 08.08.2011
I tried what Calg00ne edited for me but it still doesn't work. The car doesn't spawn.
Donya, that code still has "ca" in it. Do i need to edit it with "index"?
Re: MySQL not loading vehicles -
Donya - 08.08.2011
yes, sorry about that. edited now
Re: MySQL not loading vehicles -
CONTROLA - 08.08.2011
Donya, your code works. Thanks a lot! But I have another problem, the Owner doesn't load: The message says: "Vehicle bought by: "