无限级目录数据库结构与方法一例

博客介绍了Folder表和File表的结构。Folder表包含目录ID、上级目录ID、目录名称和说明等字段;File表包含文档ID、所属目录ID、文档名称和内容等字段,涉及数据结构和SQL相关知识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Folder 表:
Folderid:目录ID,自动编号
FolderParentID:上级目录ID,Int
FolderName:目录名称,Varchar
FolderDescription:目录说明,Varchar

File 表:
FileID:文档ID,自动编号
FileFolderID:所属目录ID,Int
FileName:文档名称,Varchar
FileDescription:文档内容,Varchar或备注(ntext)

functionGetAllChildID(id)
'取得FolderID为id的目录下所有子目录的FolderID,以半角逗号分开
dimarrID
arrID=id
Setrsdir=Conn.Execute("SelectFolderID,FolderParentIDfrom[Folder]whereFolderParentID="&id&"")
ifrsdir.eofandrsdir.bofthen
setrsdir=nothing
GetAllChildID=arrID
exitfunction
else
whilenotrsdir.eof
arrID=arrID&","&GetAllChildID(rsdir("FolderID"))
rsdir.movenext
wend
endif
setrsdir=nothing
GetAllChildID=arrID
endfunction


'从表File中取得某个目录下所有文档的Sql
dimAllChildID
AllChildID=GetAllChildID(5)'取得FolderID为5下所有目录的FolderID
AllfileSql="SelectFileID,FileNamefrom[File]whereFileFolderIDin("&AllChildID&")"
<xmp></xmp>

functionFolderPath(id)
'得到一个目录的完整路径
dimPathstr,NewPathstr
Setrsdir=Conn.Execute("SelectFolderID,FolderName,FolderParentIDfrom[Folder]whereFolderID="&id)
ifrsdir.bofandrsdir.eofthen
Pathstr=""
else
Pathstr="<ahref=""Folder.asp?FolderID="&rsdir("FolderID")&""">"&rsdir("FolderName")&"</a>>"&Pathstr
ifrsdir("FolderParentID")<>0then
Pathstr=FolderPath(rsdir("FolderParentID"))&Pathstr
endif
endif

NewPathstr=Pathstr
setrsdir=nothing
FolderPath=NewPathstr
endfunction

dimfolderpathstr
folderpathstr=FolderPath(67)
response.writefolderpathstr'输出(技术文档>Web开发>ASP>CodeSample>表单>)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值