note 28302 added to function.mysql-fetch-array
| From: | hanskrentel at yahoo dot de | Date: | Wed, 08 Jan 2003 19:25:40 +0000 |
| Subject: | note 28302 added to function.mysql-fetch-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-41854@lists.php.net to get a copy of this message | ||
for the problem with fields containing null values in an associated array, feel free to use this
function. i've got no more problems with it, just drop it in your script:
/*
* mysql_fetch_array_nullsafe
*
*
* get a result row as an enumerated and associated array
* ! nullsafe !
*
* parameter: $result
* $result: valid db result id
*
* returns: array | false (mysql:if there are any more rows)
*
*/
function mysql_fetch_array_nullsafe($result) {
$ret=array();
$num = mysql_num_fields($result);
if ($num==0) return $ret;
$fval = mysql_fetch_row ($result);
if ($fval === false) return false;
$i=0;
while($i<$num)
{
$fname[$i] = mysql_field_name($result,$i);
$ret[$i] = $fval[$i]; // enum
$ret[''.$fname[$i].''] = $fval[$i]; // assoc
$i++;
}
return $ret;
}
--
http://www.php.net/manual/en/function.mysql-fetch-array.php
http://master.php.net/manage/user-notes.php?action=edit+28302
http://master.php.net/manage/user-notes.php?action=delete+28302
http://master.php.net/manage/user-notes.php?action=reject+28302