Generate Menu based on database structure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi guys,

I need to generate a menu based on the content structure of my database.

The data is structured using an 'id' & 'parent' relationship, for eg:

id

parent

title

1

0

Home Page

6

1

My Page 2

9

6

My Page 3

15

9

My Page 4

21

6

My Page 5

22

9

My Page 6

23

22

My Page 7

24

22

My Page 8

25

1

My Page 9

28

25

My Page 10

I need to create a recursive loop that will create the menu. The text in
the brackets is what I'm trying to achieve, the rest is just for
aesthetics & ease of reading.
(The children of the row id=1 are the top of the menu tree, ie they will
be the menu categories at the top of the web page to display the menu
when the mouse hovers over it.)
(Each menu item, being a menu, will have a href to it's id number.)

My Page 2 (Menu_1)
    My Page 3 (Menu_1_1)
        My Page 4 (Menu_1_1_1)
        My Page 6 (Menu_1_1_2)
            My Page 7 (Menu_1_1_2_1)
            My Page 8 (Menu_1_1_2_2)
    My Page 5 (Menu_1_2)
My Page 9 (Menu_2)
    My Page 10 (Menu_2_1)

I just can't for the life of me get the numbering to work correctly in
the recursion.
I seem to get things like (1_1_2_1_2_3_1_2_3_4) which I can see the
pattern in, but it's obviously not what I'm after..

Appreciate your help.
Thanks, Gav.


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux