php - Need to fetch table so that every row has Primary ID for key (ZEND) -


need fetch database in order can key primary key of feched table (or column select point out). example

select id, name account; array(   0 => array(id => 12345, name => dude),   1 => array(id => 12356, name => other dude) ) 

and need is

array(   12345 => array(id => 12345, name => dude),   12356 => array(id => 12356, name => other dude) ) 

thanks!

if not tied zend_db_table can use more direct approach , more control on queries.

$db = zend_db_table::getdefaultadapter(); $select = $db->select()->from('users',array('id', 'login'));  //select id, login users $result = $db->fetchassoc($select); //this magic happens 

if can array can transform using function:

/**  * transforms associative array 'id'=>$column (or 'id'=>array(columns))  * @param array $array - associative array  * @param string|array $value - column use value (or array of columns)  * @param string  - optional column use key  * @return type array -   */ function transformtable($array, $col, $key = 'id') {     $tmp = array();      if (is_array($col)) {         foreach ($array $item) {             foreach ($col $value) {                 $tmp[$item[$key]][$value] = $item[$value];             }         }     } else {         foreach ($array $item) {             $tmp[$item[$key]] = $item[$col];         }     }      return $tmp; } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -