Ich habe folgendes Thema schon eröffnet nur leider hat die komplett am ziel vorbei geführt auch mit Titel so das ich es jetzt richtig machen möchte.
Jetzt hab ich auch selber schon was gemacht. Es geht darum das es sich beliebig tief verschachteln lässt. Also muss ich ja irgendwo und irgendwie die funktion wieder aufrufen nur wo und wie?
PHP-Code:
<?
//Array was dann aus der Datenbank kommt (nachgebaut)
$ergebnis_test= array(
array
(
group_id=>1,
parent_group_id=>NULL,
partnerid=>12673,
),
array
(
group_id=>2,
parent_group_id=>1,
partnerid=>12673,
),
array
(
group_id=>3,
parent_group_id=>2,
partnerid=>12673,
),
array
(
group_id=>18,
parent_group_id=>1,
partnerid=>12673,
),
array
(
group_id=>26,
parent_group_id=>3,
partnerid=>12673,
),
);
//funktion für baumstruktur
function tree( $parent_id, $array)
{
$count = count ($array);
$score = array();
$groups = array();
$big = array();
for($i=0; $i<= $count-1; $i++)
{
if($array[0]['group_id'] >= $parent_id)
{
$score[]= $array[$i]['parent_group_id'];
$groups[] = $array[$i]['group_id'];
$output = $groups[$i] ." => ". $score[$i];
echo '<pre>' . print_r( $output, 1 ) . '</pre>';
}
if($score[$i] > $parent_id)
{
$big[] = $score[$i];
echo '<pre>' . print_r( $big, 1 ) . '</pre>';
}
}
}
$parent_id = 1;
tree($parent_id, $ergebnis_test);
?>

Kommentar