当前位置: 移动技术网 > IT编程>开发语言>Asp > asp实现树型结构

asp实现树型结构

2017年12月12日  | 移动技术网IT编程  | 我要评论
蛙蛙推荐:asp实现树型结构     选择自 onlytiancai 的 blog  
关键字   蛙蛙推荐:asp实现树型结构 
出处    

 <!-- 
-----------[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")
%> 

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网