Jump to content

How to build a tree menu from mysql


dhimo

Recommended Posts

Hello everyone. Anyone have any idea on how to list all the records from this mysql table.As you can see it has main categories and subcategories, wich are identified by parent id and how deep they go.I am using php mysql.So how can i list them where each child is listed under parent id. like a tree menu rightAny ideas anyone? Thanks in advancetbl categories---------------------------------------------------------------------| id | cat_name | parent_id | depth |---------------------------------------------------------------------| 1 | Mobiles | 0 | 0 |---------------------------------------------------------------------| 2 | Computers | 0 | 0 |---------------------------------------------------------------------| 3 | Nokia | 1 | 1 |---------------------------------------------------------------------| 4 | Motorola | 1 | 1 |-----------------------------------------------------------------------| 5 | N70 | 3 | 2 |----------------------------------------------------------------------| 6 | KRZR | 4 | 2 |----------------------------------------------------------------------| 7 | Acer | 2 | 1 |------------------------------------------------------------------------| 8 | IBM | 2 | 1 |------------------------------------------------------------------------| 9 | TravelMate | 7 | 2 |-----------------------------------------------------------------------| 10 | ThinkPad | 8 | 2 |------------------------------------------------------------------------

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...