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
Post a Comment