naja, statt foreach ($data ...) machst du ein:
PHP-Code:
$sql = "SELECT * FROM menu order by parent_id";
if (! ($db_erg = mysql_query( $sql )) {
echo "Es konnten keine Einträge gefunden werden.";
die;
}
$root = new CAT (0, 'root', 0);
while ($c = mysql_fetch_array( $db_erg, MYSQL_ASSOC)) {
$res = $root->insert (new CAT ($c['id'], $c['menu_name'], $c['sort']), $c['parent_id']);
if (! $res) {
print_r ($c);
die ('kann c nicht einsortieren!');
}
}
$root->output();
// und dann musst du eben noch output anpassen()
// z.b:
public function output ($indent = -1) {
if ($this->id != 0) {
echo str_repeat (' ' , $indent);
echo $this->name . "<br>\n";
}
$this->sort();
foreach ($this->children as $chld) {
$chld->output ($indent+1);
}
}
btw: welche php-version verwendest du?
wenn < 5.3 dann setze erstmal private $children_sorted = true;
damit nicht sortiert wird.