FAQ

note 107008 added to function.mysql-fetch-assoc

Danbrown
Jan 3, 2012 at 9:57 pm
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
reply

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 2 | next ›

2 users in discussion

Gorm: 1 post Danbrown: 1 post