Array Multidimensional from mysql result

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hitser
    New Member
    • Sep 2011
    • 1

    Array Multidimensional from mysql result

    Hi all ... I have the following problem I can not achieve the desired format of an array.

    I have:

    while ($ row = mysql_fetch_ass oc ($ result))
    {
    $ alias = $ row ['Alias​​'];
    $ read = (int) $ row ['Read'];
    $ data [$ alias] [] = $ read;
    }

    and I produce this array:

    Code:
    {"310-Amb":[23,24,24,25],
    "310-Nev1":[5,5],
    "310-Nev2":[6,6],
    "310-Nev3":[5,5,4,4,5,4,5,5,5,4,4,5,5]}
    and I need this format:

    Code:
    [{"name":"310-Amb","data":[23,24,24,25]},
    {"name":"310-Nev1","data":[-74]},
    {"name":"310-Nev2","data":[5]},
    {"name":"310-Nev3","data":[5,6,6,5,5,4,4,5,4,5,5,5]}]
    This is my Query

    Code:
    SELECT read.Id, read.Fecha, read.Hora, productos.Producto, neveras.Alias, neveras.Min, neveras.Max, read.Lectura FROM read Inner Join neveras ON read.Nevera_Id = neveras.Id Inner Join productos ON neveras.Producto = productos.Id WHERE Hora between SUBTIME(CURTIME() , '03:00:00') And CURTIME() And read.$TipoClienteX = $IdX ORDER BY Alias, Hora Asc
    Thank you all for the help
Working...