0

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!!

Fabio
  • 23,183
  • 12
  • 55
  • 64
Andrada
  • 13
  • 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: http://stackoverflow.com/questions/8656089/solution-for-fatal-error-maximum-function-nesting-level-of-100-reached-abor – Lefsler May 16 '13 at 14:20
  • 1
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://www.brightmeup.info/article.php?a_id=2). – NullPoiиteя May 16 '13 at 14:26

1 Answers1

0

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.

Manu Clementz
  • 1,807
  • 12
  • 19