php - recursive function call in binary tree -
i have table ft_individual store information binary tree comprises of attributes id,user_name,active(to represent user active or not ),position(l left, r right),and father_id.... want number of child’s in left position of particular user number of child’s in left position of user.
i made recursive function call not working. using php codeigniter frame work......help
$l_count=$this->tree_model->childcount($user_i,'l');  $r_count=$this->tree_model->childcount($user_i,'r');   inside model.
public function childcount($user_id='',$position='')     {                  $this->db->select('id');             $this->db->from('ft_individual');             $this->db->where('father_id',$user_id);             $this->db->where('position',$position);             $this->db->where('active','yes');             $result=$this->db->get();             foreach ($result->result() $row)             {                $id= $row->id;             }               if($id!='')             {                    return (1+childcount($id,'l')+childcount($id,'r'));              }            else             {                    return 1;              }        }      
you should call function childcount method of class, add $this->
return (1 + $this->childcount($id,'l') + $this->childcount($id,'r'));       
Comments
Post a Comment