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

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>表单>)

你可能感兴趣的:(数据结构,sql,Web,asp)