宇宙最强txt下载:ASP递归赋值问题,望高手帮忙解决下

来源:百度文库 编辑:高校问答 时间:2024/05/06 02:54:40
我现在用asp做个东西,需要用到递归:读取无限级分类,通常我用sub做,这样可以在代码中使用response.write,输出正常,可是由于现在代码编写的特殊性,我必须使用function完成该项操作,问题就出在这里:只能输出第一层的值。以下给出简单示例代码以便于理解问题:
1.参数解释:
@rootid 读取数据的层次,比如无限级分类里面子类别的父类别的id编号
2.测试数据
id rootid sortname
-------------------
1 0 AAAA
2 0 BBBB
3 1 aaaaaa
4 1 bbbbb
5 2 cccccc
4.sub程序(显示达到要求)
<%
sub showsort(rootid)
//rootid参数检验,在此略
set rs=server.createobject("adodb.recordset")
sql="select id,rootid,sortname from cms_sort where rootid="&rootid&""
rs.open sql,conn,1,1
if not rs.eof then
do while not rs.eof
response.write rs("sortname")
call showsort(rs("id"))
rs.movenext
loop
end if
rs.close
set rs=nothing
end sub
%>
调用 <% call showsort(0) %> 得到结果
AAAAA
aaaaa
bbbbb
BBBBB
ccccc
4.function程序(显示未达到要求)
<%
function showsort(rootid)
//rootid参数检验,在此略
set rs=server.createobject("adodb.recordset")
sql="select id,rootid,sortname from cms_sort where rootid="&rootid&""
rs.open sql,conn,1,1
if not rs.eof then
do while not rs.eof
showsort=showsort&rs("sortname")
call showsort(rs("id"))
rs.movenext
loop
end if
rs.close
set rs=nothing
end function
%>
调用<%= showsort(0) %>显示
AAAAA
BBBBB

问题补充:如何在function中得到期望的显示结果!谢谢各位 回帖的先!!!!!!
感谢二楼的,不过问题是这样,现在必须赋值输出!!

<%
function showsort(rootid)
//rootid参数检验,在此略
set rs=server.createobject("adodb.recordset")
sql="select id,rootid,sortname from cms_sort where rootid="&rootid&""
rs.open sql,conn,1,1
if not rs.eof then
do while not rs.eof
showsort=showsort&rs("sortname")
showsort=showsort(rs("id"))
rs.movenext
loop
end if
rs.close
set rs=nothing
end function
%>

假如把sub里的程序,丝毫不改的移到function里试试吧

我感觉,当时输出比付值输出要可靠点,呵呵,个人使用习惯吧。