How to put a mysql integrer in a message? -
MineiriinHo - 01.11.2016
Hi, I want to put a mysql var in a text message in my server.
Ex: I want to get the vehicle owner name and put it in a client message...
Okay, this is the command:
PHP код:
CMD:checarplaca(playerid, params[])
{
static
id = 0;
if (GetFactionType(playerid) != FACTION_POLICE)
return SendErrorMessage(playerid, "Vocк precisa ser um policial.");
if (sscanf(params, "d", id))
return SendSyntaxMessage(playerid, "/checarplaca [vehicleid]");
if (!IsValidVehicle(id) || Car_GetID(id) == -1)
return SendErrorMessage(playerid, "You specified an invalid ID.");
SendClientMessage(playerid, -1, "The owner of this vehicle is %s :)"//, the syntax of the mysql here?);
// And the mysql var here :p
return 1;
}
Enum
PHP код:
enum carData {
carID,
carExists,
carModel,
carOwner,
Float:carPos[4],
carColor1,
carColor2,
carPaintjob,
carLocked,
carMods[14],
carImpounded,
carImpoundPrice,
carFaction,
carWeapons[5],
carAmmo[5],
carVehicle
};
MySQL examples
PHP код:
forward Car_Load();
public Car_Load()
{
static
rows,
fields,
str[128];
cache_get_data(rows, fields, g_iHandle);
for (new i = 0; i < rows; i ++) if (i < MAX_DYNAMIC_CARS)
{
CarData[i][carExists] = true;
CarData[i][carID] = cache_get_field_int(i, "carID");
CarData[i][carModel] = cache_get_field_int(i, "carModel");
CarData[i][carOwner] = cache_get_field_int(i, "carOwner");
CarData[i][carPos][0] = cache_get_field_float(i, "carPosX");
CarData[i][carPos][1] = cache_get_field_float(i, "carPosY");
CarData[i][carPos][2] = cache_get_field_float(i, "carPosZ");
CarData[i][carPos][3] = cache_get_field_float(i, "carPosR");
CarData[i][carColor1] = cache_get_field_int(i, "carColor1");
CarData[i][carColor2] = cache_get_field_int(i, "carColor2");
CarData[i][carPaintjob] = cache_get_field_int(i, "carPaintjob");
CarData[i][carLocked] = cache_get_field_int(i, "carLocked");
CarData[i][carImpounded] = cache_get_field_int(i, "carImpounded");
CarData[i][carImpoundPrice] = cache_get_field_int(i, "carImpoundPrice");
CarData[i][carFaction] = cache_get_field_int(i, "carFaction");
for (new j = 0; j < 14; j ++)
{
if (j < 5)
{
format(str, sizeof(str), "carWeapon%d", j + 1);
CarData[i][carWeapons][j] = cache_get_field_int(i, str);
format(str, sizeof(str), "carAmmo%d", j + 1);
CarData[i][carAmmo][j] = cache_get_field_int(i, str);
}
format(str, sizeof(str), "carMod%d", j + 1);
CarData[i][carMods][j] = cache_get_field_int(i, str);
}
Car_Spawn(i);
}
for (new i = 0; i < MAX_DYNAMIC_CARS; i ++) if (CarData[i][carExists]) {
format(str, sizeof(str), "SELECT * FROM `carstorage` WHERE `ID` = '%d'", CarData[i][carID]);
mysql_tquery(g_iHandle, str, "OnLoadCarStorage", "d", i);
}
return 1;
}
format(string, sizeof(string), "DELETE FROM `plants` WHERE `plantID` = '%d'", PlantData[plantid][plantID]);
Re: How to put a mysql integrer in a message? -
AndySedeyn - 01.11.2016
When using specifiers (
%s,
%d,
%i, ...) in a string, you must format it:
PHP код:
new formatString[45];
format(formatString, sizeof(formatString), "The owner of this vehicle is %s", "A person's name");
SendClientMessage(playerid, -1, formatString);
%s in this example is replaced by
"A person's name" and then put into the format variable called
formatString (minus the quotation marks, of course).
You will have to do exactly that but instead of having a static string, you must reuse the variable that holds the owner's name. You'll have to send an extra query to retrieve the name from the row of which the database ID is equal to
CarData[id][carOwner].