get value from database - 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)
+--- Thread: get value from database (
/showthread.php?tid=512065)
get value from database -
jcvag44800 - 08.05.2014
Hello,
I would like to know how I can get the value of ID 3 in the field "Modelid" in mysql ? (in cars table)
Regards
Re: get value from database -
Konstantinos - 08.05.2014
pawn Код:
"SELECT model FROM cars WHERE id = 3"
Re : get value from database -
jcvag44800 - 08.05.2014
Ok, I did this:
Код:
format(query, sizeof(query), "SELECT model FROM cars WHERE id = %d LIMIT 1",i);
mysql_query(query);
CarInfo[i][cModel] = mysql_store_result();
printf("model: %d",CarInfo[i][cModel]);
But, I have "model: 1", or it's 555
Have you an idea ?
Re: get value from database -
Konstantinos - 08.05.2014
Don't assign what mysql_store_result returns to the array because it returns 1 on success (your case) and 0 on failure.
pawn Код:
mysql_query(query);
mysql_store_result();
CarInfo[i][cModel] = mysql_fetch_int();
mysql_free_result();
printf("model: %d",CarInfo[i][cModel]);
Re : get value from database -
jcvag44800 - 08.05.2014
Thank you
Re : get value from database -
jcvag44800 - 08.05.2014
I want to have the value of a float, I make this:
Код:
format(query, sizeof(query), "SELECT pos_x FROM cars WHERE id = %d LIMIT 1",i); mysql_query(query);
mysql_store_result();
new Float:pos_x;
CarInfo[i][cLocationx] = mysql_fetch_float(pos_x);
mysql_free_result();
But, I get an error:
local variable "pos_x" shadows a variable at a preceding level (new Float

os_x; )
error 035: argument type mismatch (argument 1) (CarInfo[i][cLocationx] = mysql_fetch_float(pos_x)
How can resolve it ?
Re: get value from database -
Konstantinos - 08.05.2014
pawn Код:
mysql_store_result();
mysql_fetch_float(CarInfo[i][cLocationx]);
mysql_free_result();