1.取出所有数据
public function teammember($id){
$next = pdo_fetchall("select id,openid,agentid from ".tablename("ewei_shop_member")." where agentid > 0");
$res = $this->GetTeamMember($next,$id);//调用
return $res;
}
2.根据父id查询(do ……while)
public function GetTeamMember($members, $mid) {
$Teams=array();//最终结果
$mids=array($mid);//第一次执行时候的用户id
do {
$othermids=array();
$state=false;
foreach ($mids as $valueone) {
foreach ($members as $key => $valuetwo) {
if($valuetwo['agentid']==$valueone){
$Teams[]="'".$valuetwo['openid']."'";//找到我的下级立即添加到最终结果中
$othermids[]=$valuetwo['id'];//将我的下级id保存起来用来下轮循环他的下级
//var_dump($othermids);
// array_splice($members,$key,1);//从所有会员中删除他
$state=true;
}
}
}
$mids=$othermids;//foreach中找到的我的下级集合,用来下次循环
} while ($state==true);
return $Teams;
}