note 107008 modified in function.mysql-fetch-assoc by danbrown
| From: | danbrown@php.net | Date: | Tue, 03 Jan 2012 21:56:55 +0000 |
| Subject: | note 107008 modified in function.mysql-fetch-assoc by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-185305@lists.php.net to get a copy of this message | ||
A function to retrieve _all_ fields as fully qualified names:
<?php
function mysql_fetch_assoc_fullname($r)
{
// Does the same thing a as mysql_fetch_assoc, but the keys are fully qualified like <table
name>.<field name>.
// That way all fields is perserved and adressable like mysql_fetch_row is.
// table name will be blank if its a computed field. F.ex: 'select 5+5 as ten' will give
array('.ten' => 10)
$f = mysql_fetch_row($r);
if($f === false) return false;
$tmp = array();
foreach($f as $k => $v)
{
$tmp[mysql_field_table($r, $k) . '.' . mysql_field_name($r, $k)] = $v;
}
return $tmp;
}
?>
--was--
A function to retrieve _all_ fields as fully qualified names:
function mysql_fetch_assoc_fullname($r)
{
// Does the same thing a as mysql_fetch_assoc, but the keys are fully qualified like <table
name>.<field name>.
// That way all fields is perserved and adressable like mysql_fetch_row is.
// table name will be blank if its a computed field. F.ex: 'select 5+5 as ten' will give
array('.ten' => 10)
$f = mysql_fetch_row($r);
if($f === false) return false;
$tmp = array();
foreach($f as $k => $v)
{
$tmp[mysql_field_table($r, $k) . '.' . mysql_field_name($r, $k)] = $v;
}
return $tmp;
}
http://php.net/manual/en/function.mysql-fetch-assoc.php