get value from database
#1

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

pawn Код:
"SELECT model FROM cars WHERE id = 3"
Reply
#3

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 ?
Reply
#4

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

Thank you
Reply
#6

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 Floatos_x; )
error 035: argument type mismatch (argument 1) (CarInfo[i][cLocationx] = mysql_fetch_float(pos_x)

How can resolve it ?
Reply
#7

pawn Код:
mysql_store_result();
mysql_fetch_float(CarInfo[i][cLocationx]);
mysql_free_result();
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)