Tutaj jest funkcja:
public function getAllSubs($id = 0, $lvl = 0) { $this->db->select('id, name, parent, delete_access'); $this->db->where('parent', $id); $this->db->order_by('name', 'asc'); $cats = $this->db->get('_calteb_category')->result_array(); $lvl++; //Tutaj juz próbowałem wszystkiego. Instrukcji warunkowych, inkrementowania na końcu funkcji, nawet dodałem opcjonalny trzeci parametr razem z instrukcją warunkową, żeby za pierwszym razem nie inkrementował, ale to nic nie wychodziło jak powinno. if($count > 0) { $this->_count_all_subs += $count; } //Tutuaj obliczam ile jest dokładnie wszystkich rekordów, bo mogę sobie powiedzmy liczyć od jakiegoś danego poziomu/menu, podanego w parametrze $id funkcji. for($i=0; $i<$count; $i++) { $cats[$i]['lvl'] = $lvl; $childs = $this->getAllSubs($cats[$i]['id'], $cats[$i]['lvl']); for($j=0; $j<count($childs); $j++) { $childs[$j]['lvl'] = $lvl; $cats[$i][] = $childs[$j]; } } } return $cats; }
A przykładowy wynik wygląda tak:
( [id] => 13 [name] => Kat-4ea3bef3d6eed [parent] => 0 [delete_access] => 0 [lvl] => 1 ( [id] => 17 [name] => Kat-4ea3c2a04eb42 [parent] => 13 [delete_access] => 0 [lvl] => 1 ( [id] => 19 [name] => Kat-4ea3d061efaf0 [parent] => 17 [delete_access] => 0 [lvl] => 2 ( [id] => 22 [name] => Kat-4ea3d0ea39427 [parent] => 19 [delete_access] => 0 [lvl] => 3 ( [id] => 53 [name] => Kat-4ea3e8c36a927 [parent] => 22 [delete_access] => 0 [lvl] => 4 ) ) ) ) )
Mógłbym prosić o jakąś podpowiedź? Jestem świadomy tego, że popełniłem jakis błąd, ale od wczoraj nie mogę go znaleść.