思路是使用遞歸循環顯示數據庫中的內容 代碼: < % '***************************************** ' 功能:樹形顯示無限級分類 ' 開發:ASP編程網 ' 網址:www.ASPprogram.cn ' 作者:wangsdong ' 注:原創文章,轉載請保留此信息,謝謝 '***************************************** depath=0 function fl(parent_id) set rs1 =server.createobject("adodb.recordset") sql="select title,id from cat where parent_id="&parent_id&" order by sort_order asc" set rs1=conn.execute(sql) If rs1.eof Then Else do while not rs1.eof title = rs1("title") id = rs1("id") for i=1 to depath response.write " " next response.write title response.write "<br>" sql2="select title,id from cat where parent_id="&parent_id&" order by sort_order asc" set rs2=server.createobject("adodb.recordset") set rs2=conn.execute(sql2) if not rs2.eof then depath=depath+3 call fl(id) end if rs2.close set rs2=nothing depath=depath-3 rs1.movenext loop End If rs1.close set rs1=nothing end function call fl(0) % >