Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the following code, and a huge ERROR : Maximum function nesting level of '100' reached, aborting!:

function getTree($id)
{
    $arr = array();
    $sql ='select * from arboree where parent_id=' . $id;
    $result = mysql_query($sql);
    while ($row = mysql_fetch_array($result)) {
        $arr[] = array(
            "Parinte" => $row["parent_id"],
            "Nod" => getTree($row["id"])
        );
    }
    return $arr;
}

getTree(1);

help please!!

share|improve this question
    
Could you please post how many lines your table have, probably your code calls the getTree more than 100 times, so you can't nest any more, there are non-recursive solutions, those are more complex, but they exist. With a big number of nested elements recursion is bad and slow. To change the limit you can see here: stackoverflow.com/questions/8656089/… –  demonofnight May 16 '13 at 14:20
1  
Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial. –  NullPoiиteя May 16 '13 at 14:26
add comment

1 Answer

As far as I know PHP itself doesn't limit recursion depth. If you are using the XDebug extension, you'll need to either increase the limit (xdebug.max_nesting_level = 100) in php.ini or use a non-recursive solution.

share|improve this answer
    
i have 11 rows in database table and i don't unde XDebug. there is no other solution? –  Andrada May 16 '13 at 14:44
    
Re-write this to not be a recursive function. –  tadman May 16 '13 at 14:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.