PHP 递归生成子级数据
时间:2024-4-30 11:16 作者:杨佳乐 分类: PHP
public function doMobileWenzhang_cbt(){
global $_GPC,$_W;
$wzid=$_GPC['wzid'];
$wzinfo=pdo_get('huoban_wenzhang',array('id'=>$wzid));
//递归查询下级访问用户
$list=pdo_fetchall("select * from ".tablename('huoban_readers')." where `zhuafanum`=1 and wzid={$wzid} ");
foreach ($list as $k=>$v){
$list[$k]['childs']=$this->cbt_dgsj($v['openid'],$v['wzid']);
}
echo "<pre/>";
var_dump($list);die;
echo json_encode(array('list'=>$list));
}
function cbt_dgsj($openid,$wzid){
//echo "1<br/>";
//echo "<pre/>";
$xjlist=pdo_fetchall("select * from ".tablename('huoban_readers')." where fromuser='{$openid}' and wzid={$wzid} ");
//var_dump($xjlist);
if(!empty($xjlist)){
foreach ($xjlist as $k=>$v){
//var_dump($xjlist);
$res=$this->cbt_dgsj($v['openid'],$v['wzid']);
$xjlist[$k]['childs']=$res;
}
/*echo "1<br/><pre/>";
var_dump($xjlist);*/
return $xjlist;
}
//var_dump($list);die;
return $xjlist;
}