| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦   
共有 267 人关注过本帖
标题:谁能把该思路的代码实现?
收藏  订阅  推荐  打印
kira007
Rank: 3Rank: 3
等级:中级会员
帖子:239
积分:2692
注册:2007-6-28
谁能把该思路的代码实现?

有无限分级类表(category),父类与子类间的关系如下:

categoryID  一级父类ID     ParentID=0

           categoryID      二级父类ID     ParentID=一级父类ID

                            categoryID     三级父类ID     ParentID=二级父类ID

                     ....................................(如此类推)..............

                                            categoryID      N级父类ID     ParentID=(N-1)级父类ID                        

'////////////////////////////////////////////////////////////////////////////////////////////////////////////////
现在我的问题是 :通过获取 表单传递过来的 参数 categoryID
如何把 categoryID 所从属的 父类的categoryID      全部找出来?

例如:传递过来的 categoryID 为第三级, 那就要 把 前两级(第一和第二级)的父类的categoryID找出来....如此类推(传递过来的 categoryID 为 n-1 级,就自动把n-2 级的父类categoryID 全部找出来 )

请问该段代码应该如何编写?思路?
2008-8-6 00:16
tianyu123
Rank: 4
等级:高级会员
威望:2
帖子:563
积分:5876
注册:2007-8-26
运用递归即可 试试

<!--#include file="conn/conn.asp" -->
<%
dim num
num=0
sub fl(ID) 'ID为传递来的值
set rs=server.createobject("adodb.recordset")
sql="select categoryID,ParentID from [category] where categoryID="& ID
rs.open sql,conn,1,1
if not(rs.bof and rs.eof) then
   num=num+1
   response.write"<tr bgcolor='#FFFFFF'><td width=100 height=30>"& num &"</td><td width=100 height=30>"&rs("ParentID")&"</td></tr>"
   fl(rs("ParentID")) '调用fl()函数,实现递归
end if
end sub
response.write"<table border=0 cellpadding=0 cellspacing=1 bgcolor='#ECECEC'>"
response.write"<tr bgcolor='#FFFFFF'><td width=100 height=30>"
response.write"categoryID</td><td width=100 height=30>ParentID</td></tr>"
fl(5) '调用函数,输出结果
response.write"</table>"
response.write"此ID共包含<font color=red>"& num &"</font>级分类<br>"
%>

改变一切,须从改变观念开始!
2008-8-6 11:38
laser2008
Rank: 2
等级:注册会员
帖子:40
积分:516
注册:2008-4-7

高手这么多,我怎么办
2008-8-6 17:55
kira007
Rank: 3Rank: 3
等级:中级会员
帖子:239
积分:2692
注册:2007-6-28

多谢 tianyu123 的帮忙,问题解决了。

生活的理想,就是为了理想的生活。
2008-8-6 18:47
共有 266 人关注过本帖
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.092272 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved