06.02.2015, 23:45
So I'm trying to make a function that you can update a specific field you want in a specific table you want with a specific value you want (so many specific )... 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:
Also I don't know if it works as I never tested it, so I need your thoughts on that too.
And then use strval to turn it to an integer back, but it doesn't seem efficient and I know there's a better solution for it with low-level scripting but I don't know how...
Forgot to mention - I did some research and I found out about the YSI/y_va but I don't know how to implement it (if possible) in my case.
Also I don't know if it works as I never tested it, so I need your thoughts on that too.
PHP код:
new szString[6] = valstr(8);
Update("players", "cash", FIELD_TYPE_INT, szString, "player_id", g_Player[playerid][ID])
PHP код:
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;
}