PHP Classes

@Aleksey(Nice class) : The Functionality U Required is added

Recommend this page to a friend!

      Parent child tree with unlimited levels  >  All threads  >  @Aleksey(Nice class) : The...  >  (Un) Subscribe thread alerts  
Subject:@Aleksey(Nice class) : The...
Summary:@Aleksey(Nice class) : The Functionality U Required is added
Messages:1
Author:mrinal nandi
Date:2011-01-20 10:17:18
 

  1. @Aleksey(Nice class) : The...   Reply   Report abuse  
Picture of mrinal nandi mrinal nandi - 2011-01-20 10:17:19
@Aleksey(Nice class) : Hi, this was just a basic class only to generate a tree structure with some interrelated elements. You can add or modify it as per your need. As an example I have added a new method "getItemPath()" (with a new property "item_path") to solve ur problem. You can download the new files after approval or just add the code in the old files as described bellow :-

A) In ParentChild.php :
1. add the property (after "var $all_childs = array();") :
var $item_path = array(); //contains the total path of a given element/node(the list of elements starting from the top level root node to the given element/node)
2. add this method (after the method "getImmediateChilds()") :
public function getItemPath($item_id,$start=true){ //returns the total path of a given item/node(the list of elements starting from the top level root node to the given item/node)

if($item_id != 0) {
$sql="SELECT * FROM `".$this->db_table."` WHERE `".$this->item_identifier_field_name."`='".$item_id."' ";
$res=mysql_query($sql);
$itemdata=mysql_fetch_assoc($res);
array_push($this->item_path,$itemdata);

if($itemdata[$this->parent_identifier_field_name]!=0) {
$this->item_path=$this->getItemPath($itemdata[$this->parent_identifier_field_name],false);
}
if ($start) {
$this->item_path=array_reverse($this->item_path);
}
}
return $this->item_path;

}


B) In "example.php" :
Add this code segment at the end :

//Getting the path of an item from the root : added on 18 january, 2011 : start
echo "<p><b>Example : the full path for element q : </b></p>";
$item_id=15;
$item_path_array=$obj_parentchild->getItemPath($item_id);
foreach ($item_path_array as $val) { echo $val['Name']."->"; }

$obj_parentchild->db_disconnect();
//Getting the path of an item from the root : added on 18 january, 2011 : end

Now run "example.php" ....