Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Returning a tree from mysql DB

Options
  • 10-07-2007 12:15am
    #1
    Registered Users Posts: 1,086 ✭✭✭


    I have a large categories list. There are sub categories and sub-sub categories?

    Is there a simple was to return all the categories in a tree like structure in alhabetical order?

    My categories table is something like this

    category_id
    category_name
    parent_category_id (The parent node of this category)

    If there is no parent node the category's parent is the root.

    I would like my results to show something like this
    -Cars
         -Ford
              -Fiesta 
              -Transit
         -Peugeot
              -206
              -306
              -406
         -Porche
              -Boxter
              -Carrera
    

    Is there a simple SQL call to capture all the nodes and return them in this tree-like fashion or will I have to complete multiple queries for the sub-levels?

    I am programming in PHP.

    Thanks in advance.


Comments

Advertisement