...

View Full Version : php tree help



o0O0o.o0O0o
12-10-2008, 03:45 AM
hi ,


I have copied this code to display the tree with ext js.
but when i click on the folder then tree expands and give me again the same folder and so on. It does not give me its children

here is the code




class tx_taw_models_ProjectCategoryListProxy{

/*
* Load tree node.
*/
function getTree($TYPO3_db,$TYPO3_db_username,$TYPO3_db_password,$TYPO3_db_host,$node){
$conn = mysql_connect($TYPO3_db_host, $TYPO3_db_username, $TYPO3_db_password);
mysql_select_db($TYPO3_db, $conn);
$nodes = $this->display_children($node);
mysql_close($conn);
print json_encode($nodes);
}

// http://www.sitepoint.com/article/hierarchical-data-database
// http://extjs.com/forum/archive/index.php/t-10082.html
// $parent is the parent of the children we want to see
// $level is increased when we go deeper into the tree,
// used to display a nice indented tree

function display_children($parent) {
// retrieve all children of $parent
$result = mysql_query( 'SELECT uid, upc_name, upc_parent, upc_order ' .
'FROM tx_taw_user_project_category ' .
'WHERE upc_parent = ' . $parent . ' ' .

'ORDER BY upc_order;');
// display each child
while ($row = mysql_fetch_array($result)) {
// Response parameters.
$path['text'] = html_entity_decode($row['upc_name']);
$path['id'] = $row['uid'];
$path['position'] = $row['upc_order'];
// Check if node is a leaf or a folder.
$cResult = mysql_query( 'SELECT uid, upc_name, upc_parent, upc_order ' .
'FROM tx_taw_user_project_category ' .
'WHERE upc_parent = ' . $row['uid'] . ' ' .

'ORDER BY upc_order;');
$cCount = mysql_num_rows($cResult);
if($cCount > 0){
$path['leaf'] = false;
$path['cls'] = 'folder';
}else{
$path['leaf'] = true;
$path['cls'] = 'file';
}

// call this function again to display this
// child's children
$nodes[] = $path;
}
return $nodes;
}


}


$treeDataModel = new tx_taw_models_ProjectCategoryListProxy;
$node = 0 ;//$_POST['node'];
if ($node == 0){ // < if itīs the first node
$node = 1; // Initial node.
}
$treeDataModel ->getTree('testdb','root','','localhost', $node);

masterofollies
12-10-2008, 04:22 AM
echo out $parent and see what you get

o0O0o.o0O0o
12-10-2008, 04:52 AM
i get 2



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum