The Endless arguments
#1

hi, I want to ask for help in the following function.

Basically I want his method of using it:
GuardarCampo (ID, Table, Field1, Value1, Field2, Value2, etc ..);

I have the following code:
PHP код:
stock GuardarCampostr(id,Tabla[], ...)
{
     new 
Args 2;
     new 
query[256];
     new 
inf_Salida[256];
     
format(inf_Salida,sizeof(inf_Salida),"UPDATE `%s` SET ",Tabla);
     do
     {
         
format(query,sizeof(query),"`%s`=%s,",getarg(Args-1), getarg(Args));
         
Args+=2;
        
strcat(inf_Salida,query);
     }
     while(
Args <= numargs()-1);
     
format(query,sizeof(query),"`%s`=%s WHERE `ID`=%d",getarg(Args-1), getarg(Args),id);
     
strcat(inf_Salida,query);
      
printf(inf_Salida);

But I have a problem and I print it this way:
pawn Код:
UPDATE `svr_cuentas` SET `s`=Ms,``=M,``=M,``= WHERE `ID`=1
It donot really a lot of use of the endless arguments (...)
Reply
#2

If you need to use a loop to format all of your SQL fields for queries then you're doing something wrong, you can just manually write them, it's bad practise to have too many fields in a table
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)