一棵小树的问题,请帮忙~~

szasp 2005-04-04 03:15:06
表a

id parentid name
1 0 aa
2 1 bb
3 2 cc

4 0 dd
5 4 ee

6 0 ff
7 6 gg
8 7 hh
9 8 ii

…………


这个是一个无限级目录树表,parentid=0的为顶级目录,现在我知道所有的顶级目录ID(也就是parentid=0的所有记录的ID值),如何才能得到每个顶级目录相对应的最末级点的ID呢?


请大伙帮个忙呀~~
...全文
112 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
szasp 2005-04-05
  • 打赏
  • 举报
回复
非常感谢西方教主的帮忙~~~~~


按您的思路我已解决问题,多谢。

小二,埋单....
wxf0104 2005-04-05
  • 打赏
  • 举报
回复
<%depth=0
'depth 记忆类别的深度 顶层类深度为1
function getchild(pid)
depth=depth+1
sql="select id,menuname from newcate where Id1="&pid
set rs=cnn.Execute(sql)
do while not rs.eof
aa=1
bb=rs("id")
Response.Write(string(depth,".")&bb&rs("menuname")&"<br/>")

'此处可嵌套循环

getchild(rs("id"))
rs.movenext()
loop
depth=depth-1
end function
getchild(14)'14是顶级ID或parentid值
%>

自己修改一下。

try...
szasp 2005-04-04
  • 打赏
  • 举报
回复
晕,自己顶一下,高手都去WC了吗?
szasp 2005-04-04
  • 打赏
  • 举报
回复
to hinavy(风中的那滴血)

不行呀~~

该页无法显示。
hinavy 2005-04-04
  • 打赏
  • 举报
回复
sql="select * from [a] where ParenetID=0"
set rs=conn.execute(sql)
if rs.eof then
'这里表示没有栏目
else
response.write ("id") '输出一级栏目ID号
elementid(rs("id"))
end if
rs.close
set rs=nothing

Sub elementid(TmpID)
sqlt="select * from [a] where ParentID="&TmpID
set rstt=conn.execute(sqlt)
if rstt.eof then
elementid="无下级了栏目"
exit Sub
else
response.write rstt("id") '输出下级的每一栏目ID号
Call elementid(rstt("id"))
end if
rstt.close
End Sub

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧