蛙蛙推荐:asp实现树型结构

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 onlytiancai 的 blog

<!--
-----------[test]表生成脚本---------------
if exists (select * from dbo.sysobjects where id = object_id(n'[dbo].[test]') and objectproperty(id, n'isusertable') = 1)
drop table [dbo].[test]
go

create table [dbo].[test] (
 [id] [int] identity (1, 1) not null ,
 [str_note] [nvarchar] (50) collate chinese_prc_ci_as null ,
 [father_id] [int] null
) on [primary]
go
-->
<!--
***********************测试数据********************
[id][str_note][father_id]
[1][电脑书籍][0]
[2][软件开发][1]
[3][硬件维修][1]
[4][asp][2]
[5][php][2]
[6][jsp][2]
[7][html][2]
[8][显示器维修][3]
[9][主板维修][3]
[10][显卡维修][3]
[11][vbs基础][4]
[12][html基础][4]
[13][ado基础][4]
[14][do语句][11]
[15][for语句][11]
[16][select语句][11]
***************************************************
-->
<%
dim strconn,conn,rs,sql
strconn="driver={sql server};server=localhost;database=wawavote;uid=sa;pwd=sa;"
dim i
i=0
function showtree(parentid)
 i=i+1
 dim rs
 set rs = server.createobject("adodb.recordset")
 sql="select id, str_note, father_id,(select str_note from test t2 where t2.id = t1.father_id) as parentname  from test t1 where t1.father_id="&cint(parentid)
 rs.open sql,strconn,1,1
 do while not rs.eof
  for j=1 to i
   response.write("---")
  next
  response.write(rs(1)&"["&rs(3)&"]<br>")
  showtree rs(0)
  i=i-1
 rs.movenext
 loop
 rs.close:set rs=nothing 
end function
sub showtable(table)
 dim rs
 set rs = server.createobject("adodb.recordset")
 sql="select * from "&trim(table)
 rs.open sql,strconn,1,1
 for i=0 to rs.fields.count-1
  response.write("["&rs.fields(i).name&"]")
 next
 response.write("<br>")
 do while not rs.eof
  for i=0 to rs.fields.count-1
   response.write("["&rs.fields(i).value&"]")
  next
  response.write("<br>")
 rs.movenext
 loop
 rs.close:set rs=nothing 
end sub
showtree(0)
showtable("test")
%>

本文关键:蛙蛙推荐:asp实现树型结构
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top