)... but the problem is the value could be a string, an integer or a float... the solution I found is to use valstr on an integer/flat before you call the function, for example:
new szString[6] = valstr(8);
Update("players", "cash", FIELD_TYPE_INT, szString, "player_id", g_Player[playerid][ID])
UpdateField(const table_name[], const table_field[], const field_type, const field_value[], const condition_field[], const condition_value)
{
new szQuery[128];
switch(field_type)
{
case FIELD_TYPE_STRING:
{
mysql_format(connectionHandle, szQuery, sizeof(szQuery), "UPDATE `%e` SET `%e` = '%e' WHERE `%e` = '%d'",
table_name, table_field, field_value, condition_field, condition_value);
}
case FIELD_TYPE_INTEGER:
{
new iValue = strval(field_value);
mysql_format(connectionHandle, szQuery, sizeof(szQuery), "UPDATE `%e` SET `%e` = '%d' WHERE `%e` = '%d'",
table_name, table_field, iValue, condition_field, condition_value);
}
case FIELD_TYPE_FLOAT:
{
new iValue = floatstr(field_value);
mysql_format(connectionHandle, szQuery, sizeof(szQuery), "UPDATE `%e` SET `%e` = '%f' WHERE `%e` = '%d'",
table_name, table_field, iValue, condition_field, condition_value);
}
}
mysql_tquery(connectionHandle, szQuery, "", "");
return 1;
}
|
This is fine if you want to update one thing at a time, but I have a feeling that you're going to list them beneath each other and in that case it's a very bad thing to do. You may want to check the ORM functions 'cause that seems pretty much like what you're trying to achieve.
|
UpdateField("factions", "faction_name", FIELD_TYPE_STRING, "New Faction Name", "faction_id", g_Faction[factionid][ID]);