纯ASP实现无限级分类
作者:Moonight 日期:2006-04-28
有客户给我们建议,能不能将产品的分类做的更方便一点,能自己来分类~
于是参考了网上的资料和方法,写了一个简单的分类。不过没有加入排序这个功能。
做个简单说明:
1。数据表:ZJ_Article
数据库字段:typeid,rootid,levels,order,fatherid,myid
2。rootid 根(顶级)类顺序+1
3。order 为同一深度的类别排序
4。levels 记录该类别的深度层次。根类深度为0,一级栏目深度为1,一次类推。
5。fatherid 记录当前类别的父类id(myid)
6。myid 当前类别id 顺序+1
7。筛选记录集时,排序为“ order by rootid,orderid,levels,typeid asc ”,否则会出现同一深度的类别排列在一起,而不是按照树形结构排列。
附上源代码(右键另存为):
点击下载此文件
在获取当前类别完整路径时,用下面的代码:
sub getpath(ID)
set rs_path=server.CreateObject("adodb.recordset")
sql="select * from ZJ_Article where typeid="&ID
rs_path.open sql,conn,1,1
if rs_path("fatherid")<>0 then
call getroot(rs_path("fatherid"))
typenames=typenames&"<b>&</b>"&rs_path("titlename")
end if
rs_path.close
set rs_path=nothing
end sub
sub getroot(MyID)
set rs_root=server.CreateObject("adodb.recordset")
sql="select * from ZJ_Article where myid="&MyID
rs_root.open sql,conn,1,1
if rs_root("fatherid")<>0 then
call getroot(rs_root("fatherid"))
typenames=typenames&"<b>&</b>"&rs_root("titlename")
end if
rs_root.close
set rs_root=nothing
end sub
在需要显示类别完整路径时
call getpath(rs("typeid"))
于是参考了网上的资料和方法,写了一个简单的分类。不过没有加入排序这个功能。
做个简单说明:
1。数据表:ZJ_Article
数据库字段:typeid,rootid,levels,order,fatherid,myid
2。rootid 根(顶级)类顺序+1
3。order 为同一深度的类别排序
4。levels 记录该类别的深度层次。根类深度为0,一级栏目深度为1,一次类推。
5。fatherid 记录当前类别的父类id(myid)
6。myid 当前类别id 顺序+1
7。筛选记录集时,排序为“ order by rootid,orderid,levels,typeid asc ”,否则会出现同一深度的类别排列在一起,而不是按照树形结构排列。
附上源代码(右键另存为):
点击下载此文件在获取当前类别完整路径时,用下面的代码:
sub getpath(ID)
set rs_path=server.CreateObject("adodb.recordset")
sql="select * from ZJ_Article where typeid="&ID
rs_path.open sql,conn,1,1
if rs_path("fatherid")<>0 then
call getroot(rs_path("fatherid"))
typenames=typenames&"<b>&</b>"&rs_path("titlename")
end if
rs_path.close
set rs_path=nothing
end sub
sub getroot(MyID)
set rs_root=server.CreateObject("adodb.recordset")
sql="select * from ZJ_Article where myid="&MyID
rs_root.open sql,conn,1,1
if rs_root("fatherid")<>0 then
call getroot(rs_root("fatherid"))
typenames=typenames&"<b>&</b>"&rs_root("titlename")
end if
rs_root.close
set rs_root=nothing
end sub
在需要显示类别完整路径时
call getpath(rs("typeid"))
评论: 3 | 引用: 5778 | 查看次数: 65374
回复
]右键另存为就可以了
asdfas,不能下载
太专业,看不懂.明白两个单词end if
发表评论
上一篇
下一篇

文章来自:
Tags: 




