right. i have a table ,
ID MediumInt Primary AutoIncrement
Name VarChar(255)
Parent MediumInt
Level MediumInt
In this table, i input records in, lets say
1 (id)
Menu 1 (name)
0 (parent)
0 (level)
2
Menu 2
3
Menu 1-a
1
1
4
Menu 1-b
1
1
5
Menu 1-b-a
4
2
the result being that i can loop the results, starting at the top, printing them to screen...
Menu 1
Menu 1 > Menu 1-a
Menu 1 > Menu 1-b
Menu 1 > Menu 1-b > Menu 1-b-a
Menu 2
the items are identified by not only the level, but by the parent - IE '5; Menu 1-b-a' parent is '4; Menu 1-b'.
thats all fine. RIIIIGHT, now you have the background, i want to put these into a drop down menu.
not a problem, just do (pseudo code) :
$sql = "select all your level 0 items";
loop all the level 0 items{
print "your option tag for the drop-down form element";
$sql = "select all the level 1 items where the parent is the same as the current level 0 id"
loop all the relevant level1 items{
print "your option tag for the drop-down form element";
};
};
none too dusty, i hear you cry... but wait - theres more.
whatever code I do, has to account for the fact we dont know how many levels there are, there is an unspecified number of levels (not unlimited, unspecified, as its specified by what the user may input).
the code i have suggested there, will only account for one level.
fix me! 😃