On Sun, May 1, 2005 10:21 am, Murray @ PlanetThoughtful said:
> <?
>
> function listProjectChildren($contid, $list=''){
>
>             if ($contid<>''){
>
>                         $arrtree = array();
>
>                         $arrtree = buildProjectTree($contid, $level=1);
>
>                         for ($i=0;$i < count($arrtree);$i++){
>
>             $list .= "'{$arrtree[$i][2]}',";
>
>                          }
>
>             }
>
>     $list = substr($list, 0,-1);
>
>     unset($arrtree);
>
>             return $list;
>
> }

The $arrtree in the function above has *NOTHING* to do with the $arrtree
in the function below.

Not connected at all, really.

> function buildProjectTree($contid, $level=1){
>
>             if ($contid<>''){
>
>                         global $arrtree;

//Start with an empty tree every time this function is called:
$arrtree = array();

>                         $sql = "SELECT contid, parid, title FROM
> tbl_content
> WHERE parid='$contid'";
>
>                         $rs = mysql_query($sql);
>
>                         while ($d= mysql_fetch_object($rs)){
>
>                                     $ind = count($arrtree);
>
>
>
>                                     $arrtree[$ind][0] = $d->title;
>
>                                     $arrtree[$ind][1] = $level;
>
>                                     $arrtree[$ind][2] = $d->contid;
>
>                                     $arrtree[$ind][3] = $d->parid;
>
>                                     buildProjectTree($d->contid,
> $level+1);
>
>
>
>                         }
>
>                         mysql_free_result($rs);
>
>             }
>
>             return $arrtree;
>
> }
>
> ?>
>
> My problem is that when I'm iterating through all of the project level
> records, it appears that the content of $arrtree is never reset. New
> entries
> are simply placed on the end, causing the "for." loop that builds the
> returned $list variable in listProjectChildren() to progressively return
> larger and larger lists of contid values. As you can see, I try to UNSET()
> the array prior to returning the $list variable, but this doesn't seem to
> help.

>
> Can anyone help me figure out what I'm doing wrong?

There is *NOTHING* in the code given here that makes it "right" to have
$arrtree be a GLOBAL variable in your function.

That means you are probably doing that wrong too.

Try it with just the line I added, and no "global $arrtree;" line.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to