<?php
class Wms_Tree
{
var $table='ot_departments';/**set default table name**/
function get_AllCID($cid)
{
$depts = array();
$depts = $this->findAllData();
$result=array();
$this->findsub($depts,$cid,$result);
return $result;
}
function findAllData(){
global $db;
$tree = array();
$rs = $db->query("select * from ".$this->table." where 1 ");
while($data = $db->fetchNextObject($rs)){
$tree[] = array('id'=>$data->id,'pid'=>$data->pid,'name'=>$data->name,'memo'=>$data->memo);
}
return $tree;
}
function findsub($a,$ids,&$result){
if(!is_array($ids)) $ids=array($ids);
foreach ($ids as $d){
$result[] = $d;
}
$dds =array();
foreach ($ids as $d){
foreach($a as $aa){
if($aa['pid']==$d){
$dds[] = $aa['id'];
}
}
}
if(empty($dds)) return $result;
else $this->findsub($a,$dds,$result);
}
}
?>
使用的时候只要先将这个类实例化,再使用就可以了
require_once('class/wms.tree.php');
$tree = new Wms_Tree();
$cids = $tree->get_AllCID($_GET['dept']);