发布我的无限级目录树(asp+access)!
数据结构如下:
'*******************************************
表 sort_class
id 自动编号
title 文本(50)
UperID 数字 默认值0 父类别ID号
SortID 数字 默认值1 当前层次编号 1 代表一级分类,以此类推
'*******************************************
程序如下
'*******************************************
<% option explicit %>
<!--#include file="conn.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无限级树</title>
</head>
<body>
<%
'定义全局变量
dim fatherID
function ShowSort(uID,sID)
dim rs,sql,title,i,j,upID,sortID,temp,fatherTree
upID=uID
sortID=sID
sql="select * from sort_class where SortID="&sortID&" and UperID="&upID
title=""
set rs = Server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1
if not rs.eof then
for i=0 to rs.recordcount-1
if sortID>1 then
'****************************************
fatherID=upID
fatherTree=ShowFatherLine(upID,sortID-1)
'****************************************
if i = rs.recordcount-1 then
title="<br>"&temp&fatherTree&"<img src=""images/L.gif"" align=""absmiddle""><img src=""images/leaf.gif"" align=""absmiddle"">"'结束情形
else
title="<br>"&temp&fatherTree&"<img src=""images/T.gif"" align=""absmiddle""><img src=""images/leaf.gif"" align=""absmiddle"">"'一般情形
end if
else
title="<br><img src=""images/folderclosed.gif"" align=""absmiddle"">"'最高级目录树
end if
Response.Write title&rs("title")
call ShowSort(rs("ID"),sortID+1)'递归
rs.movenext
next
'else
end if
rs.close
set rs=nothing
end function
function isNext(sID,uID)
dim rs,sql
sql="select count(*) from sort_class where id>"&sID&" and SortID="&uID
'Response.Write sql
set rs=conn.execute(sql)
isNext = rs(0)
set rs=nothing
end function
function ShowFatherLine(fID,fSortID)
dim rs,sql
if fSortID=1 then'最后
sql="select count(*) from sort_class where id>"&fID&" and SortID="&fSortID
set rs=conn.execute(sql)
ShowFatherLine=parentTree(rs(0))
set rs=nothing
else
sql="select count(*) from sort_class where id>"&fID&" and SortID="&fSortID
set rs=conn.execute(sql)
ShowFatherLine=ShowFatherLine(fatherID,fSortID-1)&parentTree(rs(0))'递归
sql="select UperID from sort_class where id="&fatherID'fatherID全局变量
set rs=conn.execute(sql)
fatherID=rs(0)
set rs=nothing
end if
end function
function parentTree(TN)
if TN=0 then
parentTree="<img src=""images/blank.gif"" align=""absmiddle"">"
else
parentTree="<img src=""images/I.gif"" align=""absmiddle"">"
end if
end function
%>
<% call ShowSort(0,1)%>
</body>
</html>
<%
conn.close
set conn=nothing
%>
'*******************************************
浏览地址 http://www.b2bcc.cn/test/tree/
下载地址 http://www.b2bcc.cn/test/tree.rar