Im figuring out which is the efficient way to fetch tree-structured data
i have a table like this
Table : food_categories
----------------------------------------------------------
| id | parent | category_name |
----------------------------------------------------------
| 1 0 Food |
| 2 1 Veg Items |
| 3 1 Non Veg Items |
| 4 2 Carrots |
| 5 2 Greens |
| 6 2 Milk |
| 7 3 Poultry |
| 8 3 Seafood |
| 9 7 Chicken |
| 10 8 Fish |
| 11 8 Prawns |
----------------------------------------------------------
the tree-structure depth is not limited here, it can go to any levels
Im thinking to fetch these like below
array(Food'=>array( 'Veg Items'=>array('carrots'=>array(),'Greens'=>array(),'Milk'=>array()),
'Non Veg Items'=>array(
'Poultry'=>array('Chicken'=>array()),
'Seafood'=>array('Fish'=>array(),'Prawns'=>array())
)
)
)
is this possible to fetch this kind of structured array?
Im using postgresql,but Im not very handy on this, read many questions here in SO and other articles explaining the similar concepts but I couldnt get exactly.
help is appreciated.