Subject OK got my Tree Menu workin. Here is the code if anyone is intressted
Author darren_pwrs
<?php
//Include head with Logon, Client Cheak and Menu in Acordance
//Also Has output buffering and sets sessions
$title='Content Tree';
require_once('head.php');

$_SESSION['ClientId']=1;

$icon = 'folder.gif';
$expandedIcon = 'folder-expanded.gif';
$file = 'dot.gif';
$via = 'viaIcon.gif';
$orphans = array();

// Link tree menu code
require_once('TreeMenu.php');

// connect to DB...
require_once('../connect.php');

// Start new Menu
$menu = new HTML_TreeMenu();
//Creat ROOT Node
$rootNode = new HTML_TreeNode(array('text' => "
ViaMedia<br>", 'icon' => $via, 'expandedIcon' =>
$via, 'cssClass'=>'via', 'expanded' => true));

// Build Node where parent is = to 0
$query = 'SELECT "ID", "ParentId", "Name" FROM "Categories"
WHERE "ParentId"=0 AND "ClientId"='.$_SESSION["ClientId"].' ORDER
BY "Name"';
$result=ibase_query($db, $query);
$i = 0;
try {
while($row = ibase_fetch_object($result)) {

$aNode = &$rootNode->addItem(new HTML_TreeNode
(array('text' => $row->Name, 'link' => "displayItem.php?ID=$row-
>ID", 'linkTarget' => 'mainFrame', 'icon' =>
$file, 'cssClass'=>'link', 'expandedIcon' => $expandedIcon)));
// Add each of these to the allNode array
using $row->ID and &$aNode
$allNodes[$i][0] = $row->ID;
$allNodes[$i][1] = &$aNode;
$i++;
}
ibase_commit($db);
ibase_free_result($result);
} catch(Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
ibase_rollback($db);
}

// Build child nodes for Categories where ParentId > 0
$query = 'SELECT "ID", "ParentId", "Name" FROM "Categories"
WHERE "ParentId">0 AND "ClientId"='.$_SESSION['ClientId'].' ORDER
BY "ID"';
$result=ibase_query($db, $query);
try{
while($row = ibase_fetch_object($result)) {

// Find the Parent Id in the Array
$i=0;
$ArraySize=sizeof($allNodes);
while ($i < $ArraySize) {
if ($allNodes[$i][0] == $row-
>ParentId) {
$foundNode = (object)$allNodes
[$i][1];
break;
}
$i++;
}

if ($i < $ArraySize) {
// Create a Child off the found Node
$newNode = &$foundNode->addItem(new
HTML_TreeNode(array('text' => $row->Name, 'link' => "displayItem.php?
ID=$row->ID", 'linkTarget' => 'mainFrame', 'icon' =>
$file, 'expandedIcon' => $expandedIcon, 'cssClass'=>'link')));
$foundNode->icon=$icon; // Change
icon because it now has a child
$foundNode->link='';// Change link
because it now has a child
$foundNode->cssClass="body";// Change
style because it now has a child
$foundNode->linkTarget='';// Change
linkTarget because it now has a child

// Add this child to the allNode Array
$i=$ArraySize;
$allNodes[$i][0] = $row->ID;
$allNodes[$i][1] = &$newNode;
} else {
// Add it to the orphan array
$i=sizeof($orphans);
$orphans[$i][0] = $row;
}
}
ibase_commit($db);
ibase_free_result($result);
ibase_close($db);
}catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
ibase_rollback($db);
}

// Clear the Orphan Array
$orphanCnt=0;
while (sizeof($orphans) > 0) {
if ($orphanCnt >= sizeof($orphans))
$orphanCnt = 0;
// Find the Parent Id in the Array
$i=0;
$ArraySize=sizeof($allNodes);
while ($i < $ArraySize) {
if ($allNodes[$i][0] == (object)$orphans
[$orphanCnt][0]->ParentId ) {
$foundNode = (object)$allNodes[$i][1];
break;
}
$i++;
}
if ($i < $ArraySize) {
// Create a Child off the found Node
$newNode = &$foundNode->addItem(new
HTML_TreeNode(array('text' => $row->Name, 'link' => "displayItem.php?
ID=$row->ID", 'linkTarget' => 'mainFrame', 'icon' =>
$file, 'expandedIcon' => $expandedIcon, 'cssClass'=>'link')));
$foundNode->icon=$icon; // Change icon
because it now has a child
$foundNode->link='';// Change link because it
now has a child
$foundNode->cssClass='body';// Change style
because it now has a child
$foundNode->linkTarget='';// Change
linkTarget because it now has a child
// Add this child to the Node Array
$i=$ArraySize;
$allNodes[$i][0] = $row->ID;
$allNodes[$i][1] = &$newNode;
// Remove the Element from the array
unset($orphans[$orphanCnt]);
}
$orphanCnt++;
}

$menu->addItem($rootNode);
$treeMenu = &new HTML_TreeMenu_DHTML($menu, array('images'
=> 'imagesAlt', 'defaultClass' => 'treeMenuDefault'));
$listBox = &new HTML_TreeMenu_Listbox($menu, array
('linkTarget' => 'mainFrame'));

?>
<script language="JavaScript" type="text/javascript">
<!--
a = new Date();
a = a.getTime();
//-->
</script>
<table width="100%">
<tr>
<td width="200">
<?php
$treeMenu->printMenu();
?>
<br /><br />
</td>
</tr>
</table>


<script language="JavaScript" type="text/javascript">
<!--
b = new Date();
b = b.getTime();

document.write("Time to render tree: " + ((b - a) / 1000) + "s");
//-->
</script>
<?php
//Include foot
require_once('foot.php');
?>