Getting a modified preorder tree traversal model (nested set) into a

    前端 未结 7 1386
    傲寒
    傲寒 2020-11-27 10:56

    I am trying to get my data which is hierarchically set up with a tree traversal model into an < ul> in order to show on my site.

    Here is my code:

    
    
            
    7条回答
    •  星月不相逢
      2020-11-27 11:28

      $linaje='';
          $lastnode='';
          $sides['izq']=array();
          $sides['der']=array();
          $print = '
        '; foreach ($array as $key1 => $value1){ //Proyectos if(strpos($info[$key1]['linaje'],'-') !== false) $compare = strstr($info[$key1]['linaje'],'-',true); else $compare = $info[$key1]['linaje']; if($linaje != ''){ if ($linaje != $compare){ $linaje= $compare; $sides['izq']=array(); $sides['der']=array(); //for($i=1;$i <= substr_count($lastnode,'`')-substr_count($value1,'`');$i++) //$print .= '
    • '; } } if ($lastnode != '') for($i=1;$i<= substr_count($lastnode,'`')-substr_count($value1,'`');$i++) $print .= '
    '; if (count($sides['der'])>0) if ($sides['der'][count($sides['der'])-1] > $info[$key1]['der']) $print .= ''; $sides['der'][] = $info[$key1]['der']; $sides['izq'][] = $info[$key1]['izq']; if ($linaje =='') $linaje = $info[$key1]['linaje']; $lastnode = $value1; } $print .= ''; echo $print;

    the difference in this is that you can render X numbers of trees, this applies to one of my projects. and I use a char as a depth reference when I fetch the rows from the DB

    提交回复
    热议问题