I want to get the main parent of chosen subcategory. I made function which recursively loop the databasse and it even get the ID but I can only echo it. I cannot return it into variable. I need to work further with the returned ID. Here is my code.
public function check_parent($parent)
{
$q = $this->db->get_where('ci_categories', array('cat_id'=>$parent));
$r = $q->row();
if ($r->cat_child > 0)
{
$this->check_parent($r->cat_child);
} else {
echo $parent;
}
}
When I use return $parent
in else I get null. Any ideas ?