MLM树-如何根据级别对节点进行计数并按级别划分佣金

时间:2018-11-01 01:43:45

标签: php mysql tree nodes mlm

我想按级别节点划分佣金级别。 拳头水平完成佣金7% 二级完成佣金14% 第三级完成了这样的佣金21%

tree image example

我尝试此代码,但输出=

array(4) {
  [3]=>
  int(0)
  [2]=>
  int(2)
  [1]=>
  int(5)
  [0]=>
  int(8)
}

输出按列计数,但我想按级别对行进行计数以划分佣金。

 $pare01= $rowfeatchdata['usr_id'];
    class LevelDepCount{
    private $level_count=array();
    /**
     * Display all child of an element
     * @return int Count of element
     */
    public function display_children($parent, $level, $isStarted=true) 
    {
    global $con; 
    if($isStarted)
     $this->level_count=array(); // Reset for new ask
    echo $sqlcan="SELECT usr_id FROM register_user WHERE refrenceid='".$parent."'";  
     $result = mysqli_query($con, $sqlcan);
     $count=0; // For the level in the section 
      while ($row = mysqli_fetch_array($result))
       {
        $data=  str_repeat(' ',$level).$row['register_user']."\n";
        $count += 1 + $this->display_children($row['usr_id'], $level+1,false); 
       }
        if(array_key_exists($level, $this->level_count))
            $this->level_count[$level]+=$count;
        else
            $this->level_count[$level]=$count;
            return $count;     
    }

    /** Return the count by level.*/ 
        public function getCountByLevel(){  
        return $this->level_count;
    }
}
$counter=new LevelDepCount();
$counter->display_children($pare01,0);
var_dump($counter->getCountByLevel());

0 个答案:

没有答案