数据库表结构:ClassID,ClassName,ParentID
代码实现:
Class T_Class
dim ClassID,ClassName,ParentID
Public Sub Add()
strSQL = "Insert into ArticleClass(ClassName,ParentID) values('" & ClassName & "'," & ParentID & ")"
Conn.Execute(strSQL)
End Sub
Public Function Combox
dim rs,sql,msg,Format
Format =" "
msg = ""
sql = "select * from ArticleClass where ParentID = 0"
set rs = Conn.execute(sql)
while not rs.eof
msg = msg & "<option value=" & rs("ClassID") & ">" & rs("ClassName") & "</option>"
if IsExistChild(rs("ClassID")) then
msg = msg & cmb(rs("ClassID"),Format)
end if
rs.movenext
wend
rs.close
set rs = nothing
Combox = msg
End Function
Private Function cmb(ByVal ClassID,ByVal Format)
dim rs,sql,msg,i,Max,iFormat
'set rs = server.CreateObject ("adodb.recordset")
msg = ""
sql = "Select * from ArticleClass where ParentID=" & ClassID
set rs = Conn.execute(sql)
Max = CountByClass(ClassID)
i = 1
iFormat = Format & "├"
while not rs.eof
if i = Max then
Format = replace(iFormat,"├","└")
else
Format = iFormat
end if
msg = msg & "<option value="&rs("ClassID") & ">" & Format &rs("ClassName") & "</option>"
i = i + 1
if IsExistChild(rs("ClassID")) then
Format = Format & " "
Format =replace(Format,"├","│")
msg = msg & cmb(rs("ClassID"),Format)
end if
rs.movenext
wend
rs.close
set rs = nothing
cmb = msg
End Function
Private Function CountByClass(ByVal ClassID)
dim rs,sql,msg
sql = "Select count(*) as Max from ArticleClass where ParentID=" & ClassID
set rs = Conn.Execute(sql)
msg = rs("Max")
rs.close
set rs = nothing
CountByClass = msg
End Function
' 是否有子类
Public Function IsExistChild(ByVal ClassID)
dim rs,sql
sql = "Select * from ArticleClass where ParentID=" & ClassID
set rs = conn.execute(sql)
if not (rs.bof and rs.eof ) then
msg = True
else
msg = False
end if
rs.close
set rs = nothing
IsExistChild = msg
End Function
End Class
无限级分类下拉菜单数据版
最新推荐文章于 2022-04-15 10:31:28 发布