龙空技术网

php递归查询

程序猿飞飞 134

前言:

而今同学们对“for循环递归php”大约比较关心,你们都想要剖析一些“for循环递归php”的相关知识。那么小编同时在网络上搜集了一些关于“for循环递归php””的相关文章,希望咱们能喜欢,大家一起来学习一下吧!

/获取拿货上级

public function getTakeGoodsMember($member_id) {

$allMember = Db::query("SELECT id,superior_userid,user_name,level_id,take_goods_userid

FROM (

SELECT

@r AS _id,

(SELECT @r := take_goods_userid FROM " . config('database.prefix') . "user WHERE id = _id) AS parent_id,

@l := @l + 1 AS lvl

FROM

(SELECT @r :=? , @l := 0) vars,

" . config('database.prefix') . "user h

WHERE @r <> 0) T1

JOIN " . config('database.prefix') . "user T2

ON T1._id = T2.id", [$member_id]);

return $this->getTreeTakeGoodsMember($allMember, $member_id, $depth = 0);

}

/**

* 获取下面团队的人不包括自己

* @param type $member_id

* @return type

*/

public function getChildMember($member_id) {

return Db::query("SELECT id,superior_userid,user_name,level_id,take_goods_userid

FROM (

SELECT

@r AS _id,

(SELECT @r := id FROM " . config('database.prefix') . "user WHERE superior_userid = _id) AS parent_id,

@l := @l + 1 AS lvl

FROM

(SELECT @r :=? , @l := 0) vars,

" . config('database.prefix') . "user h

WHERE @r <> 0) T1

JOIN " . config('database.prefix') . "user T2

ON T1._id = T2.superior_userid", [$member_id]);

}

//获取下级

public function getDownline($allMember, $userid, $depth = 0) {

$arr = array();

foreach ($allMember as $v) {

if ($v['superior_userid'] == $userid) {

$v['depth'] = $depth + 1;

$arr[] = $v;

$arr = array_merge($arr, $this->getDownline($allMember, $v['id'], $depth + 1));

}

}

return $arr;

}

标签: #for循环递归php #php递归