关于无限分级的一种算法思路
Friday, 19. May 2006, 03:45:51
一种无限分级的算法思路,可用于任何应用无限分类的地方,比如菜单、新闻、产品等。
(其实是用到了递归算法)
调用:PrintClass 0,1
设置:添加的时候把顶级的Class的ParentId设定为0,ChildId设定为1
备注:ClassName-类别名称,ParentId-父级Id,ChildId-所处等级,顶级为1,二级为2...
数据表结构
实现函数
(其实是用到了递归算法)
调用:PrintClass 0,1
设置:添加的时候把顶级的Class的ParentId设定为0,ChildId设定为1
备注:ClassName-类别名称,ParentId-父级Id,ChildId-所处等级,顶级为1,二级为2...
数据表结构
Create Table tClass( Id int identity(1,1) not null , ClassName varchar(50) , ParentId int , ChildId int , primary key(Id) )
实现函数
'*************************************
'Coded By hooline 2006.5.19
'Email:hooline#gmail.com
'Msn:peace.zhou#msn.com
'**************************************
function PrintClass(ParentId,ChildId)
dim objRs,strSql,i
dim strSpace
set objRs=server.CreateObject("adodb.recordset")
strSql="Select * from tClass where ParentId="&ParentId&""
objRs.Open strSql,objConn,3,1
if not objRs.EOF then
strSpace=""
while not objRs.EOF
for i=1 to ChildId-1
strSpace=strSpace+"--"
next
response.Write strSpace&objRs("ClassName")&"<br />"
PrintClass objRs("Id"),ChildId+1
objRs.MoveNext
strSpace=""
wend
end if
objRs.Close
set objRs=nothing
end function







