Welcome Guest, Not a member yet? Register   Sign In
Hierarchical <ul><li> from MySql
#11

[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:
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']],'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<sup>L</sup>');
                    else
                    $this->tree($this->menu[$v['id']],'&nbsp;&nbsp;&nbsp;<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


Messages In This Thread
Hierarchical <ul><li> from MySql - by El Forum - 12-15-2007, 04:51 PM
Hierarchical <ul><li> from MySql - by El Forum - 12-16-2007, 02:25 AM
Hierarchical <ul><li> from MySql - by El Forum - 12-16-2007, 09:22 PM
Hierarchical <ul><li> from MySql - by El Forum - 12-16-2007, 09:40 PM
Hierarchical <ul><li> from MySql - by El Forum - 12-17-2007, 04:20 PM
Hierarchical <ul><li> from MySql - by El Forum - 12-18-2007, 06:00 AM
Hierarchical <ul><li> from MySql - by El Forum - 12-18-2007, 08:53 AM
Hierarchical <ul><li> from MySql - by El Forum - 12-18-2007, 09:04 AM
Hierarchical <ul><li> from MySql - by El Forum - 12-20-2007, 02:01 AM
Hierarchical <ul><li> from MySql - by El Forum - 10-25-2009, 01:49 PM
Hierarchical <ul><li> from MySql - by El Forum - 10-26-2009, 04:14 AM
Hierarchical <ul><li> from MySql - by El Forum - 08-04-2010, 09:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB