MySQL查询父类的全部子类ID

查询父类的N个子类信息

#获取子集全部id
public function getWhereDepartmentSon($department_id,$shouci=true){
    $this->erp_department = new model();
    $data = $this->erp_department->field('group_concat(department_id) as department_id')->where("find_in_set(parent_id,'$department_id')")->find();
    static $str = '';
    if($shouci){
        $str = '';
    }
    foreach ($data as $k=>$v){
        if (!empty($v)){
            $this->getWhereDepartmentSon($v,false);
        }
        $str .= $v.',';
    }
    return ltrim($str,',');
}

你可能感兴趣的:(Mysql,SQL递归)