无限级分类递归法(超简单)

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<select name="categoryid">  
<%
'表名:category
'字段名:categoryid,category,OrderID,parentID
TimesDB="../Data/#TimesShop.asp"
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&TimesDB&"")
On Error Resume Next
 Set conn = Server.CreateObject("ADODB.Connection")
 conn.open connstr

 

sort(0)
dim ii
ii=0
sub sort(selec)
 sql="select * from category where ParentID = "&selec&" order by OrderID"
 Set Rs1=Conn.Execute(sql)
 do while not rs1.eof
if selec=0 then
%>
<option value="<%=int(rs1("categoryid"))%>">|…<%=rs1("category")%></option>
<%
else
%>
<option value="<%=int(rs1("categoryid"))%>">|<%=string(ii," ")%>|…<%=rs1("category")%></option>
<%
end if
ii=ii+1
 sort rs1("categoryid")
ii=ii-1
 rs1.movenext
 loop
rs1.close
Set Rs1 = Nothing
end sub

%>
</select> 

posted on 2018-01-03 09:16  欢欢ta爸  阅读(191)  评论(0编辑  收藏  举报

导航