can someone help me make recursive function work in CI.Below is my code i tried but nothing is shown on the browser.When i try to use the code as helper it produces infinite loop.
public function printMenu($id=''){
$this->db->select('*');
$this->db->from('drop_menu');
$this->db->where('id', $id);
$query = $this->db->get();
foreach($query->result_array() as $row){
echo "<li><a href=\"#\">".$row['name'] ."</a>";
if(hasChildren($id)){
echo "<ul>";
//Call the function again with menu's id as the parameter
printMenu($id);
echo "</ul>";
}// end of if loop
echo "</li>";
}
}
public function hasChildren($menuId =''){
$query = $this->db->get_where('drop_menu',array('id'=>$menuId));
return $query->row_array();
if($this->db->num_rows() > 0){
return true;
}else{
return false;
}
}