树形结构的东西,主要是数据库结构的设计。CREATE TABLE [ts_department] ( [id] [int] IDENTITY(1, 1) NOT NULL, -- 层次 [parent_id] [int] NOT NULL DEFAULT(0), [root_id] [int] NOT NULL DEFAULT(0), [depth] [int] NOT NULL DEFAULT(1), [sort_key] [varchar] (200) NOT NULL DEFAULT(' '), [name] [varchar] (80) NOT NULL, PRIMARY KEY ([id]), UNIQUE ([sort_key]) -- 排序关键字不能重复 ) 这是我的数据库结构,可以根据你的需求,将 [parent_id] [int] NOT NULL DEFAULT(0), [root_id] [int] NOT NULL DEFAULT(0), [depth] [int] NOT NULL DEFAULT(1), [sort_key] [varchar] (200) NOT NULL DEFAULT(' '), 这四个字段做适当的删除,但 [sort_key] [varchar] (200) NOT NULL DEFAULT(' '), 不能删除。=================一代过去,一代又来,地却永远长存。日头出来,日头落下,急归所出之地。 风往南刮,又往北转,不住的旋落,而且返回转行原道,江河都往海里转,海 却不满,江河从何处流,仍归何处。
' SetSortKey ' @param varID : ' @param varParentID : ' @return Private Sub SetSortKey(ByVal varID, ByVal varParentID) Dim lngRootID, strDepth, strSortKey Dim strSql Dim objString Set objString = New GString ' Read Parent Row data If varParentID > 0 Then strSql = "SELECT * FROM ts_department WHERE id=" & varParentID OpenRecordset strSql If Not adoRst.BOF And Not adoRst.EOF Then lngRootID = adoRst("root_id") strDepth = adoRst("depth") + 1 strSortKey = adoRst("sort_key") End If Else lngRootID = -1 strDepth = 1 strSortKey = "" End If ' Set Current Row data strSql = "SELECT * FROM ts_department WHERE id=" & varID OpenRecordset strSql If Not adoRst.BOF And Not adoRst.EOF Then If lngRootID = -1 Then adoRst("root_id") = adoRst("id") Else adoRst("root_id") = lngRootID End If adoRst("depth") = strDepth adoRst("sort_key") = strSortKey & objString.Dec2Hex(adoRst("id"), 6) adoRst.Update End If End Sub这是我写的生成sort_keyr函数,你可以试试。 里面我用到了自己写的类。 代码是ASP的,改到PHP很容易。=================一代过去,一代又来,地却永远长存。日头出来,日头落下,急归所出之地。 风往南刮,又往北转,不住的旋落,而且返回转行原道,江河都往海里转,海 却不满,江河从何处流,仍归何处。
你的这个页面正是我想实现的,挺不错的,可以把源码和数据表发给我吗?我的email是[email protected] 在此,先谢谢你,如果你嫌分不够,那么以后,我再给你加。好吗?
[id] [int] IDENTITY(1, 1) NOT NULL,
-- 层次
[parent_id] [int] NOT NULL DEFAULT(0),
[root_id] [int] NOT NULL DEFAULT(0),
[depth] [int] NOT NULL DEFAULT(1),
[sort_key] [varchar] (200) NOT NULL DEFAULT(' '), [name] [varchar] (80) NOT NULL,
PRIMARY KEY ([id]),
UNIQUE ([sort_key]) -- 排序关键字不能重复
)
这是我的数据库结构,可以根据你的需求,将
[parent_id] [int] NOT NULL DEFAULT(0),
[root_id] [int] NOT NULL DEFAULT(0),
[depth] [int] NOT NULL DEFAULT(1),
[sort_key] [varchar] (200) NOT NULL DEFAULT(' '),
这四个字段做适当的删除,但
[sort_key] [varchar] (200) NOT NULL DEFAULT(' '),
不能删除。=================一代过去,一代又来,地却永远长存。日头出来,日头落下,急归所出之地。
风往南刮,又往北转,不住的旋落,而且返回转行原道,江河都往海里转,海
却不满,江河从何处流,仍归何处。
' @param varID :
' @param varParentID :
' @return
Private Sub SetSortKey(ByVal varID, ByVal varParentID)
Dim lngRootID, strDepth, strSortKey
Dim strSql
Dim objString Set objString = New GString ' Read Parent Row data
If varParentID > 0 Then
strSql = "SELECT * FROM ts_department WHERE id=" & varParentID
OpenRecordset strSql
If Not adoRst.BOF And Not adoRst.EOF Then
lngRootID = adoRst("root_id")
strDepth = adoRst("depth") + 1
strSortKey = adoRst("sort_key")
End If
Else
lngRootID = -1
strDepth = 1
strSortKey = ""
End If ' Set Current Row data
strSql = "SELECT * FROM ts_department WHERE id=" & varID
OpenRecordset strSql
If Not adoRst.BOF And Not adoRst.EOF Then
If lngRootID = -1 Then
adoRst("root_id") = adoRst("id")
Else
adoRst("root_id") = lngRootID
End If
adoRst("depth") = strDepth
adoRst("sort_key") = strSortKey & objString.Dec2Hex(adoRst("id"), 6) adoRst.Update
End If
End Sub这是我写的生成sort_keyr函数,你可以试试。
里面我用到了自己写的类。
代码是ASP的,改到PHP很容易。=================一代过去,一代又来,地却永远长存。日头出来,日头落下,急归所出之地。
风往南刮,又往北转,不住的旋落,而且返回转行原道,江河都往海里转,海
却不满,江河从何处流,仍归何处。