Find the top category in tree structure, i am using this
echo getTopCategory($category_id); exit; // returning empty value
function getTopCategory($catid) {
$CI = & get_instance();
$CI->db->select('*');
$CI->db->from('categories');
$CI->db->where('id', $catid);
$query = $CI->db->get();
$result = $query->row();
//return $catid; // for testing return working
if($result->parent_id==0){
//echo $catid -- working result 350
return $catid; // root parent, not successfully returning the result
}else{
getTopCategory($result->parent_id);
}
}
if i use echo inside the getTopCategory($catid) it correctly giving the parent category id but it not returning date to getTopCategory($category_id);