Need some help to determine the amount of recursive calls in PHP

Posted by Ben Fransen on Stack Overflow See other posts from Stack Overflow or by Ben Fransen
Published on 2010-05-05T11:18:43Z Indexed on 2010/05/05 11:38 UTC
Read the original article Hit count: 329

Filed under:
|

Hi all,

I've got a, I think fairly easy question, but this is bugging me for a while now. So I figured, maybe I can get some help here.

Since recursive functions are always a bit tricky, and sometimes a bit unclear to me, I keep struggling to create a nice working solution to get my menudata.

In one of my classes I have this function, which gives me all menu-items recursivly. The thing I want is to determine at which recursionlevel a certain object was retrieved so I can create a nicely looking HTML output with indents for the levels of nesting.

public function GetObjectList($parentID = 0, $objectlist = null)
{
    if(is_null($objectlist))
    {
        $objectlist = new ObjectList("Model_Navigation");   
    }           

    $query  = MySQL::Query("SELECT * FROM `Navigation` WHERE `WebsiteID` = ".SITE_ID. " AND `LanguageID` = ".LANG_ID." AND `ParentID` = ".$parentID);

    while($result = MySQL::FetchAssoc($query))
    {           
        $object = new Model_Navigation();

        $object->ID             = $result["ID"];
        $object->WebsiteID      = $result["WebsiteID"];
        $object->LanguageID     = $result["LanguageID"];
        $object->ParentID       = $result["ParentID"];
        $object->Name           = $result["Name"];
        $object->Page           = Model_Page::GetObjectByID($result["PageID"]);
        $object->ExternalURL    = $result["ExternalURL"];
        $object->Index          = $result["Index"];
        $object->Level          = [here lies my problem];
        $objectlist->Add($object);

        self::GetObjectList($object->ID, $objectlist);
    }

    return $objectlist;
}

Hope to hear from you!

Greetings from Holland,

Ben Fransen

© Stack Overflow or respective owner

Related posts about php

Related posts about recursion