[MySQL] Update through a function
#1

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.
PHP код:
new szString[6] = valstr(8);
Update("players""cash"FIELD_TYPE_INTszString"player_id"g_Player[playerid][ID]) 
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...
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(connectionHandleszQuerysizeof(szQuery), "UPDATE `%e` SET `%e` = '%e' WHERE `%e` = '%d'",
                
table_nametable_fieldfield_valuecondition_fieldcondition_value);
        }
        case 
FIELD_TYPE_INTEGER:
        {
            new 
iValue strval(field_value);
            
mysql_format(connectionHandleszQuerysizeof(szQuery), "UPDATE `%e` SET `%e` = '%d' WHERE `%e` = '%d'",
                
table_nametable_fieldiValuecondition_fieldcondition_value);
        }
        case 
FIELD_TYPE_FLOAT:
        {
            new 
iValue floatstr(field_value);
            
mysql_format(connectionHandleszQuerysizeof(szQuery), "UPDATE `%e` SET `%e` = '%f' WHERE `%e` = '%d'",
                
table_nametable_fieldiValuecondition_fieldcondition_value);
        }
    }
    
mysql_tquery(connectionHandleszQuery"""");
    return 
1;

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.
Reply


Messages In This Thread
[MySQL] Update through a function - by Itzhak E. - 06.02.2015, 23:45
Re: [MySQL] Update through a function - by Vince - 07.02.2015, 00:27
Re: [MySQL] Update through a function - by Itzhak E. - 07.02.2015, 00:46

Forum Jump:


Users browsing this thread: 1 Guest(s)