Reply to Recursive function and formatting string for javascript tree

Your name:

Reply:


Posted by Charles Kline on 05/24/05 18:41

Hi all.

I can't seem to figure this one out. I am trying to output a string
for a javascript that builds a DHTML tree. The sample string looks
like this:

[
['Executive Director', null, null,
['Executive Assistant ', null, null],
['Operations Director', null, null,
['Information Technology Director', null, null,
['Information Technology Analyst', null, null]
]
],
['Finance Director', null, null],
['Human Resources Director', null, null],
['Program Services Director', null, null]
]
]

My class contains these two functions to make this happen:

function generateOrg() {
$this->getDepts(0,1);
$str = "[". $this->str."]";
return ($str);
}

function getDepts ( $parent, $level ) {
$sql = 'SELECT BudgetedOrganization.* ';
$sql .= 'FROM BudgetedOrganization ';
$sql .= 'WHERE BudgetedOrganization.boSuperiorOrgID = ' .
$parent;

$rs = $this->retrieveData($sql);
$totalRows = mysql_num_rows($rs);
if ($totalRows > 0)
{
while($row = mysql_fetch_array($rs)){
$currRow = 0;
$this->str .= "['" . $row['boOrgName'] . "',null,null";

($totalRows == $currRow) ? $delim = "," : $delim =
"],";

$this->str .= $delim;
$this->getDepts($row['boOrgID'],$level+1);
$currRow++;

}
}

return($this->str);
}


Here is the output I am getting from my database, and the format is
not right. I have played with it for hours and still can't figure out
how to get the brackets and commas formatted properly to represent
the data tree properly.

['Organization XYZ',null,null],
['Operations',null,null],
['Finance',null,null],
['Information Technology',null,null],
['Program Services',null,null],
['Program Support',null,null],
['Provider Resources',null,null],
['MOST',null,null],
['Family Resources',null,null],
['Family Resources - Chatham Site',null,null],
['Team 13',null,null],
['Team 14',null,null],
['Enhanced Programs',null,null],
['Teen Parent Program',null,null],
['External Relations',null,null],

]

AND here is is when it is nested the way I want it (I did this by hand):

[
['Organization XYZ',null,null,
['Operations',null,null,
['Finance',null,null],
['Information Technology',null,null]
],
['Program Services',null,null,
['Program Support',null,null]
['Provider Resources',null,null,
['MOST',null,null]
],
['Family Resources',null,null,
['Family Resources - Chatham Site',null,null,
['Team 13',null,null],
['Team 14',null,null]
],
['Enhanced Programs',null,null,
['Teen Parent Program',null,null]
]
],
],
['External Relations',null,null]
]
]


Any help would be great. I am stuck.

Thanks,
Charles

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация