加两个字段,一个是父ID,如果是顶层,父ID就为0,一个是是否有下级,0元1有,一个函数就可解决,在函数中间调用本函数,找出了父层,再找他是否有下级,如果有,再找父ID为本ID的栏目
'==================================================
' Procedure name: Listecityclass
' Function: Display system classification
' Parameter: ID------the system ID to match
'==================================================
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 the 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) ' invokes another function, in the following
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 C Lassorder 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) ' calls this function
F_reco.movenext
Format_i=format_i-1
Next
End If
F_reco.close:set f_reco=nothing
End Sub