ASP根據(jù)父ID遞歸得到所有子類ID的函數(shù)代碼是網(wǎng)站設(shè)計(jì)中很重要的一部分內(nèi)容,今天創(chuàng)新互聯(lián)網(wǎng)站建設(shè)小編就來和大家說說這些知識(shí)吧。我們先要在網(wǎng)頁(yè)中加兩個(gè)字段,一個(gè)是父ID,如果是頂層,父ID就為0,一個(gè)是是否有下級(jí),0元1有,一個(gè)函數(shù)就可解決,在函數(shù)中間調(diào)用本函數(shù),找出了父層,再找他是否有下級(jí),如果有,再找父ID為本ID的欄目
==================================================
'過程名:listecityclass
'作用:顯示系統(tǒng)分類
'參數(shù):id ------ 要匹配的系統(tǒng)ID
'==================================================
Sub listecityclass(id)
dim F_reco,F_total,F_n,F_classid,F_classname,F_classlayer
set F_reco=Server.CreateObject("ADODB.Recordset")
F_reco.Open "select classid,classname,classlayer from ws_ecityclass where classparent=0 and classlist=0 order by classorder Asc",conn,1,1
F_total=F_reco.recordcount
if F_total>0 then
for F_n=1 to F_total
format_i=1
F_classid=F_reco(0)
F_classname=F_reco(1)
F_classlayer=F_reco(2)
response.write "<option"
if F_classlayer=0 then response.write " value=" & F_classid
if id=F_classid then response.write " selected"
response.write ">" & F_classname & "</option>"
if F_classlayer=1 then call listecityclass_(id,F_classid)'調(diào)用另一個(gè)函數(shù),在下面
F_reco.movenext
next
end if
F_reco.close : set F_reco=nothing
End Sub
Sub listecityclass_(id,iid)
dim F_reco,F_total,F_n,F_m,F_classid,F_classname,F_classlayer
set F_reco=Server.CreateObject("ADODB.Recordset")
F_reco.Open "select classid,classname,classlayer from ws_ecityclass where classparent="&iid&" and classlist=0 order by classorder Asc",conn,1,1
F_total=F_reco.recordcount
if F_total>0 then
for F_n=1 to F_total
F_classid=F_reco(0)
F_classname=F_reco(1)
F_classlayer=F_reco(2)
format_i=format_i+1
response.write "<option"
if F_classlayer=0 then response.write " value=" & F_classid
if id=F_classid then response.write " selected"
response.write ">"
for F_m=format_i to 2 step -1
response.write " "
if F_m=2 then
if F_n=F_total then response.write "└" else response.write "├"
end if
next
response.write F_classname & "</option>"
if F_classlayer=1 then call listecityclass_(id,F_classid) '調(diào)用本函數(shù)
F_reco.movenext
format_i=format_i-1
next
end if
F_reco.close : set F_reco=nothing
End Sub