MySQL Problem -
pop.nicku - 14.01.2012
Hi,
I have this vehicle system:
PHP код:
enum cInfo
{
cModel,
Float:cLocationx,
Float:cLocationy,
Float:cLocationz,
Float:cAngle,
cColorOne,
cColorTwo,
cOwner[MAX_PLAYER_NAME],
cDescription[32],
cValue,
//cRegistration,
cOwned,
cLock,
ownedvehicle,
cAlarm,
cDestroyed[MAX_VEHICLES],
cInsurance,
cPaintJob,
cID,
};
new CarInfo[51][cInfo];
and this loading function (made by Cameltoe):
PHP код:
stock LoadCar() // You might want to make this an public so you could call it on an timer.
{
new Query[255],atext[4],ltext[4];
for(new id; id < sizeof(CarInfo); id++) // Makes an loop so all vehicles get loaded.
{
format(Query, sizeof(Query), "SELECT * FROM vehicles WHERE CarID = %d", id);
mysql_query(Query); // Querys the "Query" Variable.
mysql_store_result(); // Stores the result from Query
if(mysql_num_rows())
{
if(mysql_fetch_row(Query)) // Splits the row
{
sscanf(Query, "p<|>e<iffffiis[25]s[25]iiiiiiiii>",CarInfo[id]);
if(CarInfo[id][cAlarm] == 1)
atext="ON";
else
atext="OFF";
if(CarInfo[id][cAlarm] == 1)
ltext="ON";
else
ltext="OFF";
printf("CarInfo: %d Owner:%s, Alarm:%s, Insurance:%d Locked: %s",id,CarInfo[id][cOwner],atext,CarInfo[id][cInsurance],ltext);
}
}
else
{
print("no car loaded");
return 0;
}
}
return 1;
}
But it doesen't load any car,it returns me "no car loaded"
Can somebody help me?
Thanks
Re: MySQL Problem -
pop.nicku - 15.01.2012
UP!
Nobody?
Re: MySQL Problem -
Ricop522 - 15.01.2012
pawn Код:
stock LoadCar() // You might want to make this an public so you could call it on an timer.
{
new Query[256],Select[50], atext[4],ltext[4];
for(new id; id < sizeof(CarInfo); id++) // Makes an loop so all vehicles get loaded.
{
format(Select, sizeof(Select), "SELECT * FROM vehicles WHERE CarID = %d", id);
mysql_query(Select); // Querys the "Query" Variable.
mysql_store_result(); // Stores the result from Query
if(mysql_num_rows())
{
if(mysql_fetch_array(Select)) // Splits the row
{
sscanf(Query, "p<|>e<iffffiis[25]s[25]iiiiiiiii>",CarInfo[id]);
if(CarInfo[id][cAlarm] == 1)
atext="ON";
else
atext="OFF";
if(CarInfo[id][cAlarm] == 1)
ltext="ON";
else
ltext="OFF";
printf("CarInfo: %d Owner:%s, Alarm:%s, Insurance:%d Locked: %s",id,CarInfo[id][cOwner],atext,CarInfo[id][cInsurance],ltext);
}
}
else
{
print("no car loaded");
return 0;
}
}
return 1;
}
Re: MySQL Problem -
[HiC]TheKiller - 16.01.2012
That script isn't a great example of loading mass amounts of information. There is a much more efficient way that would take 50x less time to load from the database. There is also no mysql_free_result which could after a while cause issues.
pawn Код:
stock LoadCar() // You might want to make this an public so you could call it on an timer.
{
new Query[255],atext[4],ltext[4], id;
mysql_query("SELECT * FROM vehicles"); // Querys the "Query" Variable.
mysql_store_result(); // Stores the result from Query
while(mysql_retrieve_row())
{
mysql_fetch_row(Query);
sscanf(Query, "p<|>e<iffffiis[25]s[25]iiiiiiiii>",CarInfo[id]);
if(CarInfo[id][cAlarm] == 1) atext="ON";
else atext="OFF";
if(CarInfo[id][cAlarm] == 1) ltext="ON";
else ltext="OFF";
printf("CarInfo: %d Owner:%s, Alarm:%s, Insurance:%d Locked: %s",id,CarInfo[id][cOwner],atext,CarInfo[id][cInsurance],ltext);
id++;
}
mysql_free_result();
return 1;
}
Re: MySQL Problem -
pop.nicku - 16.01.2012
@Ricop522 - I'm using G-sTyLeZzZ MySQL plugin and when I try to compile the gm it returns me this error:
error 017: undefined symbol "mysql_fetch_array"
@[HiC]TheKiller - It still doesen't work..
LE: I fixed it, i just checked the mysql connection before the LoadCar function and forks fine now.
Thank you