note 62561 deleted from function.mysql-fetch-assoc by betz

From: Date: Sat, 04 Mar 2006 11:18:02 +0000
Subject: note 62561 deleted from function.mysql-fetch-assoc by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-104823@lists.php.net to get a copy of this message
Note Submitter: paintedgautheir at gmail dot com ---- Heres something i think is really useful This function takes an array from a mysql_fetch_assoc() and updates mysql sql with the array. After you make changes to it of course. Note it will also keep null values null. <?php $sql = "SELECT * FROM player WHERE login = '$user_login'"; $result = mysql_query($sql) or die($sql); $myrow = mysql_fetch_assoc($result); function assoc_array_to_mysql() { global $array; $go = 1; $update = 'update player set '; while ($check = $go) { if ($i) { $update .= key($array); $check = current($array); if (isset($check)) { $update .= '=\''.current($array).'\''; } else { $update .= '=null'; } } else { $key = key($array); $current = current($array); $end = "where $key = $current"; } next($array); $check = key($array); if (isset($check)) { $go = 1; if ($i) {$update .= ', '; } } else { $go =0; $update .= ' '.$end; } $i="I win"; } $result = mysql_query($update) or die(mysql_oops($update)); } ?>

« previous php.notes (#104823) next »