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:
$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 .= '';
$print .= '- '.substr($value1,substr_count($value1,'`')).'';
if ($info[$key1]['der'] - $info[$key1]['izq'] == 1)
$print .= '
';
if ($key1 == count($info)-1)
for($i=1;$i <= substr_count($lastnode,'`')-1;$i++)
$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