方法一:T-SQL递归查询
with Dep as
(
select Id,DeptCode,DeptName from Department where Id=1
union all
select d.Id,d.DeptCode,d.DeptName from Dep
inner join Department d on dep.Id = d.ParentDeptId
)
select * from Dep
方法二:PL/SQL递归查询
select Id,DeptCode,DeptName
from Department
start with Id = 1
connect by prior Id = ParentDeptId
function get_category($id){$str=array()
//$sql = "select * from biao where id=$id"查询节点,自己写吧
$result = array('id'=>,'parent_id'=>)//查询结果一个数组格式
if($result){
$str = get_category($result['parent_id'])
$str[]=$result
}
return $str
}
}
调用get_category()就行了,$str第一个元素是节点本身,去掉就行了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)