//my id's hierarchy for the example: 0 -> 71 -> 78 -> 80 function parent_id($cat_id) { $db = new ps_DB; $q = "SELECT * FROM #__{vm}_category_xref "; $q .= "WHERE #__{vm}_category_xref.category_child_id='$cat_id' "; $db->setQuery($q); $db->query(); return $db->f("category_parent_id"); } echo parent(80); //returns 78 -> OK! function niveau($cat_id,$A){ echo "$cat_id($A) -> "; if(parent_id($cat_id)==0) { return $A; } else { niveau(parent_id($cat_id),$A+1); } } echo niveau(80,0); //returns '80(0) -> 78(1) -> 71(2) ->' but i'd like only the '2'