public static function fromDatabase() { $themen = new Themen(); $query = 'select parent, Name from Thema order by parent, Name;'; $result = mysql_query($query); $allChilds = array(); while (list($parent, $child) = mysql_fetch_row($result)) { $themen->add($parent, $child); $allChilds[] = $child; } foreach ($themen->themen as $parent => $childs) { if ($parent == Themen::ROOT_NAME) { continue; } if (array_search($parent, $allChilds) === false) { $themen->add(Themen::ROOT_NAME, $parent); } } return $themen; }