Help required for a query to generate menu hierarchy

Discussion in 'Databases' started by abhilashdas, Aug 27, 2008.

  1. #1
    Hellow,
    I have a table which holds an entire menu hierachy. Table looks likes below..

    ex.
    id menu parent
    1 'Top1' 0
    2 'Top2' 0
    3 'Top3' 0
    4 'Top1.1' 1
    5 'Top1.2' 1
    6 'Top3.1' 3

    and so on(can grow to any level)... so that the entire hierarchy is stored in a single table.

    Now the problem is that i want to display the menu hierarchy in a combo box with submenu's intended from the top menu.

    ex.
    Top1
    ..Top1.1
    ..Top1.2
    Top2
    Top3
    ..Top3.1
    and so on...

    I have solved it using a recursive function with so many queries....
    But is it posible to do this in a straight forward way???
    Or is it possible to represent this hierarchy in a better way???
    :rolleyes:
    Thanx in advance.
     
    abhilashdas, Aug 27, 2008 IP
  2. cont911

    cont911 Peon

    Messages:
    50
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    just read entire table using one query and then use recursive function to build menu hierarchy
     
    cont911, Aug 27, 2008 IP