For a long time now I have built my multi-level website navigation menus using a top level query which gets, you guessed it, my top level navigation options (parent options) and then inside the while loop of this query I run a second query which gets all sub options (child options) based on the primary key of the top level navigation.
My navigation database table structure contains among other things, the primary autoincrement value, and 2 other fields, parent and child where parent is a 1 if it is a top level option and child is the primary key value of the parent.
illustrated below:
pk | title | parent | child |
1 | Home | 1 | 0
2 | About | 1 | 0
3 | History | 0 | 2
4 | Other | 0 | 2
and so on...
This has worked fine but is there a better way of building my menu structure rather running the sub query inside the parent query each time?
Surely not everyone builds multi level menu options like this!!?
Thanks for reading.