您现在的位置: Gufang > 博客 > 学无止境 > 正文
ASP递归查询无限级分类

ASP无限级分类有很多种方法,今天先说说递归查询方式,该方式代码简单、容易维护、缺点是执行效率不高、排序困难!

<#%
’定义第一级分类
sub mainfl()
dim rs
set rs=conn.execute("select id,F_id,F_name from F_fl where F_id=0 order by id desc")
if not rs.eof then
do while not rs.eof
response.write rs(2) & "
"
call subfl(rs(0),"  |-") ’循环子级分类
rs.movenext
if rs.eof then exit do ’防上造成死循环
loop
end if
end sub
’定义子级分类
sub subfl(fid,strdis)
dim rs1
set rs1=conn.execute("select id,F_id,F_name from F_fl where F_id="&fid&" order by id desc")
if not rs1.eof then
do while not rs1.eof
response.write rs1(2) & "
"
call subfl(rs1(0),"  "&strdis) ’递归子级分类
rs1.movenext
if rs1.eof then
rs1.close
exit sub
end if
loop
end if
end sub

’至此已经完成了,看看真的很简单,两个子程序就搞定了,等有空的时候再写个复杂点的,不过执行效率比这个就好多了!我测试的时候分到六级的时候执行时间已经是40多毫秒了!
’最后直接调用mainfl()就行了

mainfl()
%#>

发表评论(0)
姓名 *
电子邮件
QQ
评论内容 *
验证问题 * 江苏省的省会是哪个城市?请填写正确答案
验证码 * 图片看不清?点击重新得到验证码