php - Infinite dynamic multi-level nested category with MySQL -


in database structure this:

---------------------- | id | name | par_id | ---------------------- | 1  | aaaa |    0   | ---------------------- | 2  | bbbb |    1   | ---------------------- | 3  | cccc |    1   | ---------------------- | 4  | dddd |    2   | ---------------------- | 5  | eeee |    2   | ---------------------- | 6  | ffff |    5   | ---------------------- 

this listed php want avoid php , sql directly made query return hierarchy looks this:

--------------------- | id | name | level | --------------------- | 1  | aaaa |   0   | --------------------- | 2  | bbbb |   1   | --------------------- | 4  | dddd |   2   | --------------------- | 5  | eeee |   2   | --------------------- | 6  | ffff |   3   | --------------------- | 3  | cccc |   1   | --------------------- 

i need change order in table , add level of depth this:

from:                 to: aaaa                  aaaa bbbb                  -bbbb cccc                  --dddd dddd                  --eeee eeee                  ---ffff ffff                  -cccc 

is possible in single sql query this?


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -