function fetchAll() { $cats = new categories(); $cats->parent = 0; $cats->find(); while ($cats->fetch()) { $this->cat_names[$cats->id] = $cats->name; $this->cats[$cats->id] = 0; $cats2 = new categories(); $cats2->parent = $cats->id; if ($cats2->find()) { $this->cats[$cats->id] = array(); while ($cats2->fetch()) { $this->cat_names[$cats2->id] = $cats2->name; $this->cats[$cats->id][$cats2->id] = 0; $cats3 = new categories(); $cats3->parent = $cats2->id; if ($cats3->find()) { $this->cats[$cats->id][$cats2->id] = array(); while ($cats3->fetch()) { $this->cat_names[$cats3->id] = $cats3->name; $this->cats[$cats->id][$cats2->id][$cats3->id] = 0; } } } } } $temp = $this->cats; $this->cats = array(); $this->cats[] = $temp; }