一个树型显示的问题。

casear_huang 2002-01-07 06:07:19
我有一个表,结构、数据如下:
id pid (pid为父id)
a01 0
a11 a01
a12 a01
a21 a11
a22 a11
a33 a21
a34 a21
我想显示为如下的树型形式,程序该如何写:
a01
|__a11
| |__a21
| | |__a33
| | |__a34
| |__a22
|__a12
...全文
167 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
yihis 2002-01-09
  • 打赏
  • 举报
回复
另外第27行是什么?
yihis 2002-01-09
  • 打赏
  • 举报
回复
??不会吧?这是我以前的一个程序,运行时没有错误:
<!--#include file="../adovbs.inc"-->
<!--#include file="../dbconn/dbconn.asp"-->
<%
function tree(officeid)
sql="select * from officedb where officeparents='"&officeid&"'"
set rs1=conn.Execute(sql)
if rs1.bof or rs1.eof then
else
while rs1.eof=false
%>
<tr><td><input type="button" value=<%=rs1("officename")%> onclick="window.open('discdisp.asp?officeid=<%=rs1("officeid")%>','discdisp','width=640,height=480,toolbar=no,menubar=no')"></td>
<td>
<table>
<%
tree(rs1("officeid"))
%>
</table>
</td></tr>
<%
rs1.movenext
wend
end if
end function
%>
<center>
<table>
<tr>
<%
tree(0)
%>
</tr>
</table>
<table>
<tr>
<td>
<input type="button" value="全体留言" onclick="window.open('discdisp.asp?officeid=0','discdisp','width=640,height=480,toolbar=no,menubar=no')">
   
<input type="button" value="我的留言" onclick="window.open('discdisp.asp?officeid=self','discdisp','width=640,height=480,toolbar=no,menubar=no')">
</td>
</tr>
</table>
</center>
guiguai 2002-01-09
  • 打赏
  • 举报
回复
关注关注~~ 哈哈~ 我被这个问题烦了好久啦
casear_huang 2002-01-09
  • 打赏
  • 举报
回复
谢谢雪狼,问题解决了。
还有风林火山,你的实在太长了,有机会再测试一下你的。
haiznan 2002-01-09
  • 打赏
  • 举报
回复
哦~~~不要忘了给分哦~~~哈哈`~~
haiznan 2002-01-09
  • 打赏
  • 举报
回复
哈哈!!!你给分吗~!!
你是呀ASP 还是JAVASCRIPT的呀~!!!
(1)ASP的
表名:BBS
字段
数据类型
说明
ID 自动编号  
RootID Int 根帖ID,本身为根帖则RootID = ID
FID Int 父帖ID,上一层帖子的ID,如是根帖则FID = NULL
Level SmallInt 根帖Level=0,其他依据回复的深度递增
Subject Char 主题

SQL 语句(须据此创建记录集 rs):

SELECT *
FROM BBS
ORDER BY BBS.RootID DESC, BBS.Level, BBS.FID, BBS.ID DESC
____________________________________________
显示树形结构的有关语句:
____________________________________________

Level = 0

Response.Write "<ul>"

While NOT rs.EOF

If rs("Level") < level Then
For i = 1 To Level-1
Response.Write "</ul>"
Next
End If

If rs("Level") > level Then
Response.Write "<ul>"
End If
Response.Write "<li>" & rs("Subject") & "</li>"

level = rs("Level")
rs.MoveNext

Wend

Response.Write "</ul>"


JAVASCRIPT(2)的

你要先建立一个<script language="JavaScript1.2" src="menu.js"></script>的js文件
内容为下

——————————————————————————
NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
ver4 = (NS4 || IE4) ? 1 : 0;

if (ver4) {
with (document) {
write("<STYLE TYPE='text/css'>");
if (NS4) {
write(".parent {position:absolute; visibility:visible}");
write(".child {position:absolute; visibility:visible}");
write(".regular {position:absolute; visibility:visible}")
}
else {
write(".child {display:none}")
}
write("</STYLE>");
}
}

function getIndex(el) {
ind = null;
for (i=0; i<document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.id == el) {
ind = i;
break;
}
}
return ind;
}

function arrange() {
nextY = document.layers[firstInd].pageY +document.layers[firstInd].document.height;
for (i=firstInd+1; i<document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.visibility != "hide") {
whichEl.pageY = nextY;
nextY += whichEl.document.height;
}
}
}

function initIt(){
if (!ver4) return;
if (NS4) {
for (i=0; i<document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";
}
arrange();
}
else {
divColl = document.all.tags("DIV");
for (i=0; i<divColl.length; i++) {
whichEl = divColl(i);
if (whichEl.className == "child") whichEl.style.display = "none";
}
}
}

function expandIt(el) {
if (!ver4) return;
if (IE4) {
whichEl = eval(el + "Child");
if (whichEl.style.display == "none") {
whichEl.style.display = "block";
}
else {
whichEl.style.display = "none";
}
}
else {
whichEl = eval("document." + el + "Child");
if (whichEl.visibility == "hide") {
whichEl.visibility = "show";
}
else {
whichEl.visibility = "hide";
}
arrange();
}
}
onload = initIt;
——————————————————————————
在body中加

<div id="KB1Parent" class="parent"><a href="#" onClick="expandIt('KB1'); return false" onMouseOver="window.status='文件夹1的状态栏信息...';return true;" onMouseOut="window.status='';return true;"><IMG SRC="i_person.gif" BORDER=0>用户管理</a></div>

<div id="KB1Child" class="child">
<a href="member/member_list.asp" target="right" onMouseOver="window.status='页面3的状态栏信息...';return true;" onMouseOut="window.status='';return true;"><img src="spacer.gif" width=20 height=11 border=0 alt=""><IMG SRC="minus.gif" BORDER=0>查询会员</a><br>
<a href="member/member_query.asp" target="right" onMouseOver="window.status='页面3的状态栏信息...';return true;" onMouseOut="window.status='';return true;"><img src="spacer.gif" width=20 height=11 border=0 alt=""><IMG SRC="minus.gif" BORDER=0>编辑会员</a></div>


------------------------------------------------
你看明白了吗!!!!!!!!!哦不要了给分哦~~~~~``
yigenhuochai 2002-01-09
  • 打赏
  • 举报
回复
UP
jsidiot 2002-01-09
  • 打赏
  • 举报
回复
u p
henry_cn 2002-01-09
  • 打赏
  • 举报
回复
我以前发布过这样的例子:
查看帖子:

http://www.csdn.net/Expert/topic/403/403923.shtm

或到“文件交流BBS”上了。
地址:http://www.csdn.net/filebbs/read_topic.asp?id=934
yihis 2002-01-08
  • 打赏
  • 举报
回复
用函数递归调用。
function tree(id)
if trim(id)=="" then
id=0
end if
sql="select * from table where pid='"&id&"'"
set rs1=conn.Execute(sql)
if rs1.bof or rs1.eof then
else
while rs1.eof=false
%>
<tr><td><%=rs1("name")%></td>
<td>
<table>
<%
tree(rs1("id"))
%>
</table>
</td></tr>
<%
rs1.movenext
wend
end if
end function
gjf888 2002-01-08
  • 打赏
  • 举报
回复
你想做树状菜单,还是要显示数据?
casear_huang 2002-01-08
  • 打赏
  • 举报
回复
help me!
casear_huang 2002-01-08
  • 打赏
  • 举报
回复
再加50分,谢谢帮忙解决这个问题。
casear_huang 2002-01-08
  • 打赏
  • 举报
回复
我需要把上面那个数据库的数据树型显示出来。
to:yihis(雪狼)
我把你的程序这样使用了,但是错误如下,你看看:ADODB.Recordset 错误 '800a0bcd'
BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。/temp/33.asp, 行27

源程序如下:
<%@Language=VbScript%>
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open Application("ConnString")
id = "a01"
Set rs1 = conn.Execute ("Select * From task where id='"&id&"'")
function tree(id)
if trim(id)="" then
id=0
end if
sql="select * from task where pid='"&id&"'"
set rs1=conn.Execute(sql)
if rs1.bof or rs1.eof then
else
while rs1.eof=false
%>
<tr><td><%=rs1("id")%></td>
<td>
<table>
<%
tree(rs1("id"))
%>
</table>
</td></tr>
<%
rs1.movenext
wend
end if
end function
tree(rs1("id"))
%>
artai 2002-01-07
  • 打赏
  • 举报
回复
ASP可以用Java Script 和VB Script 寫的~~
想用什麼程序?
casear_huang 2002-01-07
  • 打赏
  • 举报
回复
asp程序
buzhidao 2002-01-07
  • 打赏
  • 举报
回复
什么程序

vbs吗?

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧