note 71387 deleted from function.mysql-query by philip

From: Date: Fri, 04 Sep 2015 19:19:43 +0000
Subject: note 71387 deleted from function.mysql-query by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-203644@lists.php.net to get a copy of this message
Note Submitter: babba at nurfuerspam dot de ---- Following function creates a minimal update query by comparing two arrays with old and new values (phpmyadmin-like). An easy way to use it in your forms is to print out the old values in hidden fields with name old[$key] and name the visible form fields new[$key]. Feel free to send comments via mail. <?php function getUpdateString($tablename, $whereclause, $old, $new) { $changedvalues = ""; foreach($old as $key => $oldvalue) { $newvalue = $new[$key]; if($oldvalue != $newvalue) { if($changedvalues != "") $changedvalues .= ", "; $changedvalues .= "".$key."="; if(!is_numeric($newvalue)) $changedvalues .= "'".$newvalue."'"; else $changedvalues .= $newvalue; } } if($changedvalues == "") return ""; return "UPDATE ".$tablename. " SET ".$changedvalues." WHERE ".$whereclause; } ?>

« previous php.notes (#203644) next »