|
Posted by Chris on 09/30/84 11:16
You keep on appending $this->str to itself. Comments are inline.
Charles Kline wrote:
> Hi all,
>
> Not sure if I am doing this right and I can't figure it out, was
> hoping someone here can help.
>
> I have an organization table in mySQL. Pretty standard. My first
> function getDepts() is working as I intend and returning the tree
> just as I like it. The new piece I added in there that is not working
> now is the call to getPositions() within the first function. What I
> am trying to do is once I get a Department, I want to loop through
> the Positions table and get the positions that are under that
> Department. This code goes haywire and loops for ever printing a huge
> list to the screen. Eventually I need to return this data not to the
> screen but into an array. Anyone see what I might have wrong in my
> logic?
>
> I have a class and it contains these two functions.
>
> function getDepts ( $parent = 0, $level = 1 ) {
> $sql = 'SELECT BudgetedOrganization.* ';
> $sql .= 'FROM BudgetedOrganization ';
> $sql .= 'WHERE BudgetedOrganization.boSuperiorOrgID = ' .
> $parent;
>
> $rs = $this->retrieveData($sql);
> if ($rs)
> {
> while($row = mysql_fetch_array($rs)){
> $num = 1;
>
> while ($num <= $level) {
> $this->str .= "\t";
> $num++;
> }
> $this->str .= $row['boOrgID'] . ", " . $row
> ['boOrgName'] . "\n";
>
> // just added this and it ain't working
> $this->str .= $this->getPositions($row['boOrgID']);
here you are appending the result of ::getPostions() to ->str
> $this->getDepts($row['boOrgID'],$level+1);
> }
> }
> return($this->str);
> }
>
> function getPositions ( $org = 0 ) {
> $sql = 'SELECT BudgetedPosition.* ';
> $sql .= 'FROM BudgetedPosition ';
> $sql .= 'WHERE BudgetedPosition.bp_boOrgID = ' . $org;
> //echo $sql;
> $rs = $this->retrieveData($sql);
> if ($rs)
> {
> while($row = mysql_fetch_array($rs)){
> $this->str .= " - " . $row['bpPositionID'] . "\n";
appending the row to ->str
> }
> }
> return($this->str);
from getPositions you are returning ->str , so getPositions is appending
each row to ->str , then returning ->str , which is then being appended
to ->str
> }
>
>
> Later....
>
> $depts = $org->getDepts();
> echo "<pre>" . $depts . "</pre>";
>
>
> Thanks,
> Charles
>
I'd say just don't append what ::getPositions() is returning.. and
remove the return call if it makes sense to do so.
Chris
Navigation:
[Reply to this message]
|