Page 1 of 1

Managing Hierarchy

Posted: Sun May 25, 2008 3:48 pm
by jurklins
If I have a table like this in MYSQL where category_parent_id = 0 if it is at top level:
Picture1 copy.gif
Picture1 copy.gif (3.45 KiB) Viewed 1149 times

How I do I display tree view like this by using php:
>>clothes
>>>>shirt
>>>>tie
>>>>trousers
>>food
>>>>indianfood
>>>>chinesefood
>>>>spanishfood

I am able to display links to every single one of them, but i dont know how to display them in tree hierachy view with proper indent to each different level. Any hints for me??? Thanks

Re: Managing Hierarchy

Posted: Sun May 25, 2008 7:16 pm
by dbemowsk
Here is a link to a good article on traversing a tree. I use the modified preorder tree traversal algorithm for the menu on my software.

http://www.sitepoint.com/article/hierar ... a-database

You should be able to figure things out from there. They even give some sample PHP code.

Re: Managing Hierarchy

Posted: Sun May 25, 2008 8:19 pm
by jurklins
Hey Thanks. I will try to figure it out .. :D