3

i have a table ft_individual which store information about a binary tree it comprises of attributes Id,User_name,Active(to represent user is active or not ),Position(L for left, R for right),and Father_id.... i want to get the number of child’s in left position of a particular user then the number of child’s in left position of a user.

i made a recursive function call but it is not working. I am 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() as $row)
            {
               $id= $row->id;
            }  
            if($id!='')
            {   
                return (1+childCount($id,'L')+childCount($id,'R')); 
            }
           else
            {   
                return 1; 
            }   
    }
5
  • 1
    Post your table structure along with values and expected result Commented May 14, 2015 at 6:21
  • please check this recursive function in correct or not........ Commented May 14, 2015 at 9:16
  • What you are getting within results post your results Commented May 14, 2015 at 9:20
  • So how can you say its not working if you're not getting value Commented May 14, 2015 at 11:23
  • actually i am expecting the total number of child’s as the output... Commented May 15, 2015 at 3:44

1 Answer 1

2

You should call the function childCount as method of a class, just add $this->

return (1 + $this->childCount($id,'L') + $this->childCount($id,'R')); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.