我为打印leveltree创建了递归函数

时间:2019-01-11 05:15:58

标签: php

function createTreeView($array, $currentParent, $currLevel = 0, $prevLevel = -1, $ul=array()) {

    foreach ($array as $categoryId => $category) {
         if ($currentParent == $category['parentid']) {                       
            if ($currLevel > $prevLevel) $ul[] = " <ul> "; 
            if ($currLevel == $prevLevel) $ul[] = " </li> ";
            $ul[] = '<li> '.$category['name'].'';
            if ($currLevel > $prevLevel) { $prevLevel = $currLevel; }
        $currLevel++; 

           $this->createTreeView($array, $categoryId, $currLevel, $prevLevel, $ul);
           $currLevel--;               
       }   
    }
       if ($currLevel == $prevLevel) 
        $ul[] = " </li>  </ul> ";       
        return $ul;
    }

我已将此递归函数用于以下函数,但它们未返回任何值

public function getLevelTreeTemplate()
{
    global $themeData;
    global $user, $conn;
    $listTree = '';
    $currentParentStrQry = $conn->query("SELECT * FROM ".DB_CLUB." WHERE user_id='".$user['id']."'");
    $currentParentStrData = $currentParentStrQry->fetch_array(MYSQLI_ASSOC);
    $currentParentStr = $currentParentStrData['ParentStr'];

    $childUserQry = $conn->query("SELECT user_id FROM ".DB_CLUB." WHERE ParentStr LIKE '%".$currentParentStr."%'");
    while($chlidUserData = $childUserQry->fetch_array(MYSQLI_ASSOC)){
        $data[] = implode(",",$chlidUserData);
    }
    $arrayCategories = array();
    $resultQry = $conn->query("SELECT * FROM ".DB_CLUB." WHERE user_id IN(".implode(',',$data).")");
    while($resultData = $resultQry->fetch_array(MYSQLI_ASSOC)){

             $arrayCategories[$resultData['user_id']] = array(
              "parentid" => $resultData['reference_id'], 
              "name" => $resultData['first_name']
             );
    }
        $themeData['levelTree'] = $this->createTreeView($arrayCategories, $currentParentStrData['reference_id']);           
        $listTree .= \MassConn\UI::view('timeline/user/list-leveltree');    
    $themeData['list_leveltree'] = $listTree;
    return \MassConn\UI::view('massconnectclub/sidebar-leveltree'); 

}

0 个答案:

没有答案