set aa=new classlist aa.id="id"//Name of the number aa.classname="classname"//Classification name aa.pid="pid"// Parent ID name aa.db_name="class"//Table name list=aa.arrylist() ?>
Copy code
Class: classlist
<% class classlist private c_id private c_db_name private c_pid private c_classname public property let id(str) c_id = str end property public property let db_name(str) c _db_name = str end property public property let pid(str) c_pid = str end property public property let classname(str) c_classname = str end property dim list() dim i,n Private Sub Class_Initialize() 'Initialize variable i=0 n=0 End Sub public function classarry(thisid,pid)'Get the subordinate ID if pid>0 then
sql="select * from "&c_db_name&" where "&c_pid&"="&thisid
else
sql="select * from "&c_db_name&" where "&c_id&"="&thisid
end if
set rs_c=conn.execute(sql)
n=n+1
do while not rs_c.eof
list(0, i)=rs_c(c_id)' is loaded into the array
list(1,i)=rs_c(c_classname)
list(2,i)=n
'n=n+1
i=i+1
thisid=classarry (rs_c(c_id),1)' is called recursively here until the last subclass
rs_c.movenext
loop
n=n-1
rs_c.close
end function
public function arrylist()' loops out all root classes
set rs_c=conn.execute("select count("&c_id&") from "&c_db_name)
lenght=rs_c(0)
rs_c.close
redim list(2,lenght)'set array
set rs1=conn.execute(" select "&c_id&" from "&c_db_name&" where "&c_pid&"=0")
do while not rs1.eof
call classarry(rs1(c_id),0)
'n=1
rs1.movenext
loop
rs1.close
arrylist=list
end function
end class
%>
Copy code
Example test:
Table class
Field
id: automatic number
classname: name
pid: parent ID
File name: test.asp
<% Set conn=Server.CreateObject("ADODB.connection") Set Rs = Server.CreateObject( "ADODB.Recordset") StrDSN = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" StrDSN = StrDSN & Server.MapPath("test.mdb") conn.Open strDSN function ins( num) str="" for ii=1 to num str=str&"|-" next ins=str end function set aa=new classlist aa.id="id" aa.classname= "classname" aa.pid="pid" aa.db_name="class" list=aa.arrylist() response.write "ID td> Name < td>Category "
for j=0 to ubound(list,2)
response.write ""&list(0,j)&""&list(1,j)&" "&list(2,j)&" "
next
response.write "
"
'response.write list(1,3)
%>
<% for i=0 to ubound(list,2)%>
<%response.write ins(list(2,i)) response.write list(1 ,i)%>
<%next%>
Copy code
Loop results:
bbs.it-home.org/code/class/test.asp
It can basically meet the usual needs.