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
note 107008 added to function.mysql-fetch-assoc
Discussion Overview
| group | php-notes |
| categories | php |
| posted | Dec 28, '11 at 12:10p |
| active | Jan 3, '12 at 9:57p |
| posts | 2 |
| users | 2 |
| website | php.net |
