请问如何做出有层次结点的树形菜单?
请问如何做出有层次结点的树形菜单? 我的数据库表中结构如下:
id upid title
1 0 A组
2 1 A001
3 1 A002
4 0 B组
5 4 B001
6 4 B002
...
要求树形菜单形式为:
A组
A001
A002
B组
B001
B002
...
请问谁有这个示例呢? 万分谢谢
------解决方案-------------------- <%
set rsb=conn.execute( "select * from tree where upid=0 ")
while not rsb.eof
response.write(rsb( "title "))
set rss=conn.execute( "select * from tree where upid= "&rsb( "upid "))
while not rss.eof
response.write(rss( "title "))
rss.movenext
wend
set rss=nothing
rsb.movnext
wend
set rsb=nothing
%>
------解决方案--------------------建议数据库结构改一下,否则循环嵌套查询估计效率会比较低,而且数据库压力也会比较大,当然,如果数据少就看你改数据结构方便不方便了
id upid title
1 0 A组
2 1 A001
3 1 A002
4 0 B组
5 4 B001
6 4 B002
改成:
id upid title flag
1 0 A组 1
2 1 A001 1
3 1 A002 1
4 0 B组 2
5 4 B001 2
6 4 B002 2
这样就可以用一条简单的语句查询出效果
dim pre
dim sql,rs
sql= "select id,title from forum_type where upid=0 order by flag,upid "
set rs=server.createObject( "adodb.recordset ")
rs.open sql,conn,1,1
if not rs.eof and not rs.bof then
do while not rs.eof
if upid=0 then
pre= " "
else
pre= " "
end if
Response.Write pre&rs(1)& " <br> "
rs.movenext
loop
else
Response.Write "没有任何菜单 "
end if
rs.close
set rs=nothing