按父级获取用户层次结构

时间:2018-08-14 09:37:30

标签: php mysql recursion out-of-memory

我正在尝试让所有孩子和大孩子以及他们的孩子都使用PHP

代码

$usrtoGet = 1;
array_push($juniors, $usrtoGet);

$sql = $db->Query("select usr_id from crm_users where usr_reporting_head=?", array($usrtoGet));
$result=$db->FetchAllArray($sql);

foreach ($result as $res) {
    $juniors[] = $res['usr_id'];
    getChildUsers($res['usr_id']);
}

function getChildUsers($res){
    global $db;
    global $juniors;

    $sql = $db->Query("select usr_id from crm_users where usr_reporting_head=?", array($res));
        $result=$db->FetchAllArray($sql);
        foreach($result as $two){
            array_push($juniors, $two['usr_id']);
            getChildUsers($two['usr_id']);
        }
    }

起初我正确地获得了期望的结果,后来又出现了错误

  

致命错误:第706行的C:\ xampp \ htdocs \ crm \ adodb \ drivers \ adodb-mysql.inc.php中的内存不足(已分配468975616)(试图分配44个字节)

我尝试调整

ini_set('memory_limit','2G');

但没有用。

如果我在函数getChildUsers的第getChildUsers($two['usr_id']);行中注释掉了,那是因为没有搜索孙子项而起作用了,有什么办法可以得到所需的解决方案吗?

0 个答案:

没有答案
相关问题