tree - mysql flat design to php nested array -


i have simple mysql user table flat design below. table ordered group5, ..., libuser ascending.

╔════════╤════════╤════════╤════════╤═══════════╗ ║ group5 │ group4 │ group3 │ group2 │ libuser   ║ ╠════════╪════════╪════════╪════════╪═══════════╣ ║ g5_1   │ g4_1   │ g3_1   │ g2_1   │ libuser_1 ║ ╟────────┼────────┼────────┼────────┼───────────╢ ║ g5_1   │ g4_1   │ g3_1   │ g2_1   │ libuser_2 ║ ╟────────┼────────┼────────┼────────┼───────────╢ ║ g5_1   │ g4_1   │ g3_1   │ g2_1   │ libuser_3 ║ ╟────────┼────────┼────────┼────────┼───────────╢ ║ g5_1   │ g4_1   │ g3_1   │ g2_2   │ libuser_4 ║ ╟────────┼────────┼────────┼────────┼───────────╢ ║ g5_1   │ g4_1   │ g3_2   │ g2_3   │ libuser_5 ║ ╟────────┼────────┼────────┼────────┼───────────╢ ║ ....   │ ....   │ ....   │ ....   │ ....      ║ ╟────────┼────────┼────────┼────────┼───────────╢ ║ g5_n   │ g4_n   │ g3_n   │ g2_n   │ libuser_n ║ ╚════════╧════════╧════════╧════════╧═══════════╝ 

i want transform flat design hierarchical nested tree. goal use fancytree.js display it.

the final nested array parents/children should ("nbcpt" attribute number of users in branch, don't pay attention it). example, there no exact link between mysql table showed above , nested array.

[ {"title": "all", "expanded": true, "folder": true, "nbcpt": 8, "children": [     {"title": "g5_1", "folder": true, "nbcpt": 4, "children": [         {"title": "g4_1", "nbcpt": 3, "folder": true, "children": [             {"title": "g3_1", "folder": true, "nbcpt": 2, "children": [                     {"title": "libuser_1", "nbcpt": ""},                     {"title": "libuser_2", "nbcpt": ""} ,                 {"title": "g3_2", "folder": true, "nbcpt": 1, "children": [                     {"title": "libuser_3", "nbcpt": ""}                 ]}             ]}         ]},         {"title": "g4_2", "folder": true, "nbcpt": 1,"children": [             {"title": "g3_3", "folder": true, "nbcpt": 1, "children": [                 {"title": "libuser_4", "nbcpt": ""}             ]}         ]}     ]},         {"title": "g5_2", "folder": true, "nbcpt": 4, "children": [         {"title": "g4_3", "folder": true, "nbcpt": 3, "children": [             {"title": "g3_4", "folder": true, "nbcpt": 2, "children": [                     {"title": "libuser_5", "nbcpt": ""},                     {"title": "libuser_6", "nbcpt": ""},                 {"title": "g2_1", "nbcpt": 1, "children": [                     {"title": "libuser_7", "nbcpt": ""}                 ]}             ]}         ]},         {"title": "g3_5", "folder": true, "nbcpt": 1, "children": [             {"title": "g2_2", "folder": true, "nbcpt": 1, "children": [                 {"title": "libuser_8", "nbcpt": ""}             ]}         ]}     ]}   ]} ] 

i read examples when data stored hierachical structure, not case here.

any idea transform flat design tree ? thank help.

in general, use postprocess callback adapt or convert source data.
the tutorial contains examples.

while not final code solves problem, may ideas request: https://github.com/mar10/fancytree/issues/431


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -