ASP Menu driving me insane
I am trying to create a menu using ASP (I have never used ASP before, im a PHP man) using values stored in a database.
basically the html layout i want is as such:
<ul>
<li>
<ul class="sub-menu">
<li class="sub-menu-li">Test</li>
</ul>
</li>
</ul>
I n开发者_如何学编程eed to loop around the root menu items rs("AD_Level") which is equal to 0 for root objects, then inside that loop, lop around anything that has the same parent id eg if the current record is AD_Level =0 and AD_Parent=5 then loop around all items with AD_Parent 5 and AD_Level != 0 and insert the values into html and so on and so forth.
Please help! I am struggling with a new language and cannot see a way to do this without losing sanity
Edit (Extracted from Comment by OP)
while not rsAdmin.eof
sPar = rsAdmin("ad_parent"
if rsAdmin("AD_Level")=0 then
while not rsAdmin2.eof
if rsAdmin2("AD_Level")<>0 and rsAdmin2("ad_parent")=sPar and rsAdmin2("AD_Sec_Level")=>2 then
response.write rsAdmin("AD_Menu")
end if
rsAdmin2.movenext
wend
end if
'' # if not rsAdmin.eof then sPar=rsAdmin("AD_parent") rsAdmin.movenext
wend
that is my code
Surely this is an obvious case for using recursion, just providing psuedo-code below since I can't really understand your menu structure very well from your code so I've not attempted to put it directly into ASP code:
For Each MenuItem at with Level=0
Display the Menu Text (if applicable)
Call GenerateSubMenu(MenuItem.ID)
Next
Function GenerateSubMenu(ID)
For Each MenuItem with Parent=ID
Display the Menu Text (if applicable)
Call GenerateSubMenu(MenuItem.ID)
Next
End Function
精彩评论