How to get an hierarchical php structure from a db table, in php array, or JSON

Posted by daniel on Stack Overflow See other posts from Stack Overflow or by daniel
Published on 2010-05-09T23:23:46Z Indexed on 2010/05/09 23:28 UTC
Read the original article Hit count: 366

Filed under:
|
|
|
|

Hi guys, can you please help me. How to get an hierarchical php structure from a db table, in php array, or JSON, but with the following format:

[{ "attributes" : {"id" : "111"}, "data" : "Some node title", "children" : [ { "attributes" : { "id" : "555"}, "data" : "A sub node title here" } ], "state" : "open" }, { "attributes" : {"id" : "222"}, "data" : "Other main node", "children" : [ { "attributes" : { "id" : "666"}, "data" : "Another sub node" } ], "state" : "open" }]

My SQL table contains the fields: ID, PARENT, ORDER, TITLE

Can you please help me with this? I'm going crazy trying to get this.

Many thanks in advance. Daniel

© Stack Overflow or respective owner

Related posts about arrays

Related posts about JSON