MLM Tree - как считать узлы в соответствии с уровнем и делить комиссию на уровень - PullRequest
0 голосов
/ 01 ноября 2018

Я хочу разделить уровень комиссии на узлы уровня. Первый уровень выполненной комиссии 7% Второй уровень завершена комиссия 14% третий уровень завершена комиссия 21%, как это

пример изображения дерева

Я пытаюсь этот код, но Output =

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

output Count by Column, но я хочу посчитать уровень строки по уровню, чтобы разделить комиссию.

 $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());
...