Re: Conditional updating...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



try this one.

just pass for $_value an array with your table fieldname as your key

   function constructUpdate( $_tbl_name, $_where, $_values )
   {
       $valstr = '';
       $firstval = false;
       if (is_array($_values)) {
           foreach( $_values as $key=>$val ) {
               if ($val != '') {
                   if( $firstval )
                       $valstr.= ',';

                   if (is_string($val)) {
                       $valstr.= " $key = '$val'";
                   } else {
                       $valstr.= " $key = $val";
                   }
                   $firstval = true;
               }
           }
       } else {
           $valstr    = $_values;
       }
       $retStr = "update $_tbl_name set $valstr";
       if( $_where )
       $retStr.= " where $_where";

       return $retStr;
   }

[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux