note 62561 added to function.mysql-fetch-assoc
| From: | paintedgautheir at gmail dot com | Date: | Fri, 03 Mar 2006 11:57:11 +0000 |
| Subject: | note 62561 added to function.mysql-fetch-assoc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-104769@lists.php.net to get a copy of this message | ||
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));
} ?>
----
Server IP: 64.71.164.2
Probable Submitter: 65.189.222.1
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-assoc.php
Edit -- http://master.php.net/note/edit/62561
Del: integrated -- http://master.php.net/note/delete/62561/integrated
Del: useless -- http://master.php.net/note/delete/62561/useless
Del: bad code -- http://master.php.net/note/delete/62561/bad+code
Del: spam -- http://master.php.net/note/delete/62561/spam
Del: non-english -- http://master.php.net/note/delete/62561/non-english
Del: in docs -- http://master.php.net/note/delete/62561/in+docs
Del: other reasons-- http://master.php.net/note/delete/62561
Reject -- http://master.php.net/note/reject/62561
Search -- http://master.php.net/manage/user-notes.php