ASP 無(wú)限級(jí)分類(lèi)實(shí)現(xiàn)
ASP遞歸無(wú)限級(jí)分類(lèi)函數(shù)
<%
'函數(shù):getCatagory
'功能:獲得分類(lèi)列表
'參數(shù):cat_arr -> 分類(lèi)數(shù)組(Rscordset:id:分類(lèi)編號(hào),pid:上級(jí)分類(lèi),classname:分類(lèi)名稱(chēng),childs:子分類(lèi))
' 按此輸出些sql語(yǔ)句,用getRows獲取得到的數(shù)據(jù)
' cat_pid -> 上級(jí)分類(lèi)編號(hào)
' cat_childs -> 下級(jí)分類(lèi)編號(hào)
' cat_select -> 選擇的分類(lèi)
' cat_dir -> 分類(lèi)級(jí)別
'返回:返回分類(lèi)列表(Option)
dim conn,cmd,rs,cat_arr
Set conn = Server.CreateObject("ADODB.Connection")
Set cmd = Server.CreateObject("ADODB.Command")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db1.mdb")
cmd.ActiveConnection = conn
cmd.CommandText = "Select * from cate order by id desc"
Set rs = cmd.Execute
cat_arr = rs.GetRows()
Set rs = Nothing
Set cmd = Nothing
Set conn = Nothing
getCatagory cat_arr,0,"","","","{$cat.dir}├─<a href=""?id={$cat.id}"" title=""分類(lèi)級(jí)別:{$cat.dir} 分類(lèi)編號(hào):{$cat.id} 分類(lèi)上級(jí)編號(hào):{$cat.pid} 分類(lèi)名稱(chēng):{$cat.name} 分類(lèi)子分類(lèi):{$cat.childs}"">{$cat.name} </a><br />"&vbcrlf
function getCatagory(byval cat_arr,byval cat_pid,byval cat_childs,byval cat_select,byval cat_dir,byval format)
dim i,tmp
if isArray(cat_arr) then
for i=0 to ubound(cat_arr,2)
if cat_arr(1,i) = cat_pid and instr("," & cat_childs & ",","," & cat_arr(0,i) & ",") = 0 then
tmp = format
if instr(tmp,"{$cat.dir}")>0 then tmp = replace(tmp,"{$cat.dir}",cat_dir)
if instr(tmp,"{$cat.id}")>0 then tmp = replace(tmp,"{$cat.id}",cat_arr(0,i))
if instr(tmp,"{$cat.pid}")>0 then tmp = replace(tmp,"{$cat.pid}",cat_arr(1,i))
if instr(tmp,"{$cat.name}")>0 then tmp = replace(tmp,"{$cat.name}",cat_arr(2,i))
if instr(tmp,"{$cat.childs}")>0 then tmp = replace(tmp,"{$cat.childs}",cat_arr(3,i))
response.write tmp
call getCatagory(cat_arr,cat_arr(0,i),cat_childs,cat_select,cat_dir & "│",format)
end if
next
end if
end function
%>
轉(zhuǎn)載的一個(gè)遞歸函數(shù),比較典型的應(yīng)用,沒(méi)有特別算法,目前我們一般常見(jiàn)的無(wú)限級(jí)分類(lèi)函數(shù)均大同小異。簡(jiǎn)單整理了一下,包括示例打包getCatagory.rar
*大類(lèi)1
└二級(jí)小類(lèi)1
└三級(jí)小類(lèi)1
└四級(jí)小類(lèi)1
└五級(jí)小類(lèi)1
*大類(lèi)2
└二級(jí)小類(lèi)2
*大類(lèi)3
數(shù)據(jù)庫(kù)說(shuō)明:數(shù)據(jù)庫(kù)db.mdb,classTable表的結(jié)構(gòu):classid類(lèi)別ID(自動(dòng)增長(zhǎng)) parentid 父級(jí)ID 默認(rèn)為0 (0代表最高級(jí)) classname類(lèi)別名,classdepth是為了記錄類(lèi)別的級(jí)數(shù) ———————————————-
| classid| classname| parentid | classdepth |
———————————————-
主要代碼:
//先取出最高級(jí)(parentid=0)的分類(lèi)
<%
set conn=server.createobject("adodb.connection")
conn.open "Provider=Microsoft.Jet.Oledb.4.0;data source="&server.MapPath("db.mdb")
set rs1=server.createobject("adodb.recordset")
sql1="select * from Classtable where parentid=0 order by classid"
rs1.open sql1,conn,1,1
if rs1.eof or rs1.bof then
response.write"還沒(méi)分類(lèi)!"
else
while not rs1.eof
id1=rs1("classid")
name1=rs1("classname")
response.write "*<a href='class.asp?id="&id1&"&name="&name1&"‘>"&name1&"</a><br>"
parentid1=rs1("parentid")
call reclass(id1)
rs1.movenext
wend
end if
rs1.close
set rs1=nothing
sub reclass(id)
‘遞歸調(diào)用函數(shù),生成一個(gè)類(lèi)別代碼
set rs=server.createobject("adodb.recordset")
sql="select * from classtable where parentid="&id
rs.open sql,conn,1,1
i=1
while not rs.eof
id0=rs("classid")
classname0=rs("classname")
parentid0=rs("parentid")
classdepth0=rs("classdepth")
brstr=""
for j=1 to classdepth0
brstr=" "&brstr
next
response.write(brstr&"└<a href='class.asp?id="&id0&"&name="&classname0&"‘>"&classname0&"</a><br>")
call reclass(id0)
rs.movenext
i=i+1
wend
rs.close
set rs=nothing
end sub
if request("a")="add" then
call add
end if
if request("name")<>"" then
%>
<table width="80%" align="center" cellpadding="0″ cellspacing="0″>
<form action="class.asp?a=add&id=<%=request("id")%>" method="post">
<tr>
<td> </td>
<td>在<font color="#FF0000″><%=request("name")%></font>添加小類(lèi)</td>
</tr>
<tr>
<td>類(lèi)別名:</td>
<td><input name="classname" type="text" id="classname"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="提交"></td>
</tr>
</form>
</table>
<%end if
sub add '添加類(lèi)別
id=request("id")
classname=request("classname")
set rs=server.createobject("adodb.recordset")
rs.open "select parentid,classdepth from classtable where classid="&id,conn,1,1
parentid=rs(0)
classdepth=rs(1)+1
rs.close
set rs=nothing
sql="INSERT INTO classtable (classname,parentid,classdepth) values ('"&classname&"‘,"&id&","&classdepth&")"
conn.execute sql
response.Write"<script>alert('添加成功!');location.href='class.asp';</script>"
end sub
%>
- mysql 無(wú)限級(jí)分類(lèi)實(shí)現(xiàn)思路
- php實(shí)現(xiàn)無(wú)限級(jí)分類(lèi)(遞歸方法)
- php 無(wú)限級(jí)分類(lèi),超級(jí)簡(jiǎn)單的無(wú)限級(jí)分類(lèi),支持輸出樹(shù)狀圖
- php實(shí)現(xiàn)無(wú)限級(jí)分類(lèi)查詢(xún)(遞歸、非遞歸)
- php實(shí)現(xiàn)無(wú)限級(jí)分類(lèi)
- ThinkPHP無(wú)限級(jí)分類(lèi)原理實(shí)現(xiàn)留言與回復(fù)功能實(shí)例
- winform樹(shù)形菜單無(wú)限級(jí)分類(lèi)實(shí)例
- php+mysql實(shí)現(xiàn)無(wú)限級(jí)分類(lèi) | 樹(shù)型顯示分類(lèi)關(guān)系
- Asp.net 無(wú)限級(jí)分類(lèi)實(shí)例代碼
- thinkphp5實(shí)現(xiàn)無(wú)限級(jí)分類(lèi)
相關(guān)文章
Asp實(shí)現(xiàn)的數(shù)據(jù)庫(kù)連接池功能函數(shù)分享
這篇文章主要介紹了Asp實(shí)現(xiàn)的數(shù)據(jù)庫(kù)連接池功能函數(shù)分享,本函數(shù)能夠加快網(wǎng)頁(yè)的訪問(wèn)速度,降低數(shù)據(jù)庫(kù)的壓力,需要的朋友可以參考下2014-07-07做文章系統(tǒng)時(shí), 如何讓長(zhǎng)篇的文章自動(dòng)換行
做文章系統(tǒng)時(shí), 如何讓長(zhǎng)篇的文章自動(dòng)換行...2006-09-09asp生成不需要數(shù)據(jù)庫(kù)的中獎(jiǎng)碼
有一個(gè)思路是:將一批唯一中獎(jiǎng)碼,錄入的到數(shù)據(jù)庫(kù),中獎(jiǎng)時(shí),取出來(lái)一條,做一個(gè)標(biāo)記,把中獎(jiǎng)碼告訴2008-07-07asp二維數(shù)組實(shí)例中的使用方法總結(jié)
筆者對(duì)asp編程不是很熟悉,而且好長(zhǎng)不用記不清了。這一次,需要保存asp的二維數(shù)組為asp文件,使用include 指令文件引用后,直接調(diào)用。使用過(guò)程中發(fā)現(xiàn)asp的二維數(shù)組相關(guān)資料很少,而且介紹簡(jiǎn)單模糊,現(xiàn)結(jié)合使用實(shí)例做個(gè)簡(jiǎn)單筆記。2023-06-06完美解決PJ的Cookies保存時(shí)限問(wèn)題!可選擇記錄登陸時(shí)長(zhǎng)!
完美解決PJ的Cookies保存時(shí)限問(wèn)題!可選擇記錄登陸時(shí)長(zhǎng)!...2007-02-02錯(cuò)誤類(lèi)型:Provider (0x80004005)未指定的錯(cuò)誤 的一個(gè)處理方法
一般情況下asp可以正常運(yùn)行,但只要連接數(shù)據(jù)庫(kù)就提示,Microsoft JET Database Engine 錯(cuò)誤'80004005'2007-04-04用asp實(shí)現(xiàn)的截取指定格式字符串的代碼
用asp實(shí)現(xiàn)的截取指定格式字符串的代碼...2007-11-11