10-26-2009, 04:14 AM
[eluser]umefarooq[/eluser]
ya coffey code will work really fine but every time you have to call sql command ever time we have query from database i worked on one code with only one query getting all parent and children and sorted properly as tree here is code
code is generating proper tree, but i was not able to put in ul and li any body can do it that's really good for CI community
ya coffey code will work really fine but every time you have to call sql command ever time we have query from database i worked on one code with only one query getting all parent and children and sorted properly as tree here is code
Code:
class Treeview{
public $counter = 0;
protected $holder ;
protected $menu = array();
function navigation(){
$sql = 'select * from menu order by ordering,parent asc';
$query = $this->db->query($sql);
$rows = $query->result_array();
foreach($rows as $row){
$this->menu[$row['parent']][$row['id']] = $row;
}
$this->tree();
}
function tree($child=array(),$space=''){
$level = $this->counter;
if(isset ($this->menu[0])&& is_array($this->menu[0]) || (is_array($child) && !empty ($child))){
$this->counter++;
$this->holder[$this->counter] = (is_array($child) && !empty ($child))?$child:$this->menu[0];
foreach ($this->holder[$this->counter] as $v){
echo $space.$v['name'].'<br />';
if(isset($this->menu[$v['id']])){
if($level)
$this->tree($this->menu[$v['id']],' <sup>L</sup>');
else
$this->tree($this->menu[$v['id']],' <sup>L</sup>');
}
}
}
}
}
code is generating proper tree, but i was not able to put in ul and li any body can do it that's really good for CI community