Napisałem funkcje rekurencyjną:
function child_counter($child_id) { if($child_id!=0) { $level++; $query6=mysql_query("SELECT categories_id,parent_id from categories where categories_id='$child_id'",$GLOBALS[db]); child_counter($d[1]); } else return $level; }
Do której podaje jako argument id rodzica z tabeli z kategoriami. Tabela jest wzorowana na OSCommerce:
CREATE TABLE IF NOT EXISTS `categories` ( `categories_id` int(11) NOT NULL AUTO_INCREMENT, `categories_image` varchar(64) DEFAULT NULL, `parent_id` int(11) NOT NULL DEFAULT '0', `sort_order` int(3) DEFAULT NULL, `date_added` datetime DEFAULT NULL, `last_modified` datetime DEFAULT NULL, `pos` int(3) NOT NULL, PRIMARY KEY (`categories_id`), KEY `idx_categories_parent_id` (`parent_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin2 AUTO_INCREMENT=130 ;
Problem w tym, że funkcja po kilku iteracjach gdy dojdzie już do rodzica równego 0 nic nie zwraca. Gdzie może być błąd?