PHP array : simple question about multidimensional array

Posted by Tristan on Stack Overflow See other posts from Stack Overflow or by Tristan
Published on 2010-04-18T23:04:33Z Indexed on 2010/04/18 23:13 UTC
Read the original article Hit count: 413

Hello,

i've got a SQL query which returns multiple rows, and i have :

$data = array(
    "nom" => $row['nom'] ,
    "prix"   => $row['rapport'],
    "average"   => "$moyenne_ge"
  );

which is perfect, but only if my query returns one row.

i tried that :

$data = array();
$data[$row['nom']]["nom"] = $row['nom'] ;
...
$data[$row['nom']]['average']  = "$moyenne_ge";

in order to have :

$data[brand1][nom] = brand1
$data[brand1][average] = 150$
$data[brand2][nom] = brand2
$data[brand2][average] = 20$
...

but when i do : json_encode($data)

i only have the latest JSON object instead of all JSON object from my request as if my array has only one brand instead of 10.

I guess i did something stupid somewhere. Thanks for your help

© Stack Overflow or respective owner

Related posts about arrays

Related posts about php