Managing Hierarchy

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jurklins
Forum Newbie
Posts: 11
Joined: Tue Apr 22, 2008 9:44 am

Managing Hierarchy

Post 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 1148 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
dbemowsk
Forum Commoner
Posts: 82
Joined: Wed May 14, 2008 10:30 pm

Re: Managing Hierarchy

Post 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.
jurklins
Forum Newbie
Posts: 11
Joined: Tue Apr 22, 2008 9:44 am

Re: Managing Hierarchy

Post by jurklins »

Hey Thanks. I will try to figure it out .. :D
Post Reply