使用存储过程,或者给每个节点加一个 Path 字段,创建节点的时候要设置,如果有数据,用PHP先填充这个字段。
解决方案 »
- 初学php,自己写了一个《石头剪刀布》小游戏
- 表单处理问题
- 这段代码怎么没有输出啊?
- 基础:关于PHP松散比较
- 为什么从网页中倒出的数据会是乱码的啊!!!急请帮忙,谢谢
- 有关分页
- 当表单提交的信息出错时,如何在后退的页面重显出提交前的信息?
- 偷个懒,请问谁有把数字形式的“钱”转换成汉字的大写形式的程序?
- 怎样实现表单<textarea>中的文本在提交后自动分段。
- Content-type: text/html PHP Warning: Unable to load dynamic library './php_mssql.dll' - 找不到指定的模块。 in Unknown on line 0
- php 文件上传的疑问
- 求一相册系统
我查询部门ID ,张三对应的部门ID为8 ,如何查出张三的所有部门ID(包括父部门ID),如8,7,3,1--建立測試環境
Create Table department
(departmenid Int,
parentid Int)
Insert department Select 60, null
Union All Select 1, 0
Union All Select 2, 1
Union All Select 3, 1
Union All Select 4, 2
Union All Select 5, 2
Union All Select 6, 3
Union All Select 7, 3
Union All Select 8, 7
GO
--建立函數
Create Function F_GetParent(@departmenid Int)
Returns @Tree Table (departmenid Int, parentid Int)
As
Begin
Insert @Tree Select * From department Where departmenid = @departmenid
While @@Rowcount > 0
Insert @Tree Select A.* From department A Inner Join @Tree B On A.departmenid = B.parentid And A.departmenid Not In (Select departmenid From @Tree) Where A.parentid Is Not Null
Return
End
GO
--測試
Select departmenid From dbo.F_GetParent(8) Order By parentid
GO
--刪除測試環境
Drop Table department
Drop Function F_GetParent
--結果
/*
departmenid
1
3
7
8
*/