MySQL multirow
#1

Here is the code:


pawn Код:
new string[128];
format(string, sizeof(string), "SELECT * FROM vehicles WHERE Owner = '%s'", Name(playerid));
mysql_query(string);
mysql_store_result();
new nv = mysql_num_rows();
if(!nv)return SendClientMessage(playerid,ErrorColor,"You don't own a vehicle.");
new idx;
new row[130];
new field[8][40];
while(mysql_fetch_row_format(row, "|"))
{
explode(row, field, "|");
formatedmessage(playerid,-1,"RESULT: %s",strval(field[5]));
idx++;
}
mysql_free_result();
I am confused with MySQL. All i want is to get the vehicle model and send it as a client message to the player.
However what i get is that; "RESULT:0OwnerName". I really don't know how this exactly works and i would appreciate some help.
Reply
#2

You should use escape strings instead of regular strings to prevent MYSQL injections (%e).


Код:
format(string, sizeof(string), "SELECT * FROM vehicles WHERE Owner = '%s'", Name(playerid));
In this code you're selecting all data. If you just want the vehicle model ID then you only need to select that row.

Код:
format(string, sizeof(string), "SELECT `vehiclemodel` FROM `vehicles` WHERE `Owner` = '%e'", Name(playerid));
But ideally all of this data should be loaded once a player logs in, and since this player is online you could just use the variables from the script rather than a MYSQL query.
Reply


Forum Jump:


Users browsing this thread: