【发布时间】:2015-07-25 16:03:33
【问题描述】:
我有一个 ft_individual 表,它存储有关二叉树的信息,它包含属性 Id、User_name、Active(表示用户是否处于活动状态)、Position(L 代表左,R 代表右)和 Father_id... . 我想获取特定用户左侧位置的孩子数量,然后是用户左侧位置的孩子数量。
我进行了递归函数调用,但它不起作用。 我正在使用PHP codeigniter框架工作......帮助
$l_count=$this->tree_model->childCount($user_i,'L');
$r_count=$this->tree_model->childCount($user_i,'R');
内部模型。
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;
}
}
【问题讨论】:
-
发布您的表结构以及值和预期结果
-
请检查这个递归函数是否正确......
-
你在结果中得到的结果发布你的结果
-
如果你没有获得价值,你怎么能说它不起作用
-
实际上我期望孩子的总数作为输出......
标签: php codeigniter recursion