the below function has recursive function for organizational chart; family_user table:
function getrel($userid)
{
$sql = 'SELECT DISTINCT * FROM family_user WHERE userid in ( SELECT DISTINCT rel_id FROM family_rel WHERE tree_id ='.$userid.')';
$query = $this->db->query($sql);
if ($query->num_rows() > 0)
{
foreach($query->result_array() as $row)
{
$user[] = $row['userid'];
if(@in_array($row['userid'],$user))
{
echo "---------->";
echo $row['userid'];
echo "</br>";
$this->getrel($row['userid']);
//echo "HAI";
}
}
// return $user; 开发者_Python百科
}
}
the above function has no limit.please resolved
The code you have posted is going to be in an infinite loop when ever the userid provide while calling the function matches in the database.
To break a recursive loop there should be a condition which exits the loop after a finite number of run.
To provide you a good solution please elaborate what you would like to achieve with your code.
精彩评论