⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Multi level menu



gede bhama

gede bhama
  • profile picture
  • Member

Posted 08 August 2014 - 14:01 PM

hi,

I have table "menuku"

- id -> autoincreament->primary key

- Id_parent

- menu

- stato

I want to display the data like this :

(between the main menu and sub ​​menu is displayed in sequence and have different spaces from the left)

multi.png

my code is

 

    function categorie()
    {
      $crud = new grocery_CRUD();
    
      $crud->set_table('menuku');
    
      /* Add this customisation for parent_relation */
      $primary_id_field  = 'id';
      $table_name   = 'menuku';
      $relation_field_name = 'id_parent';
      $parent_field   = 'id_parent';
      $title_field   = 'menu_en';
      $title_display_as  = 'Select menu';
      $crud->display_as('id_parent','Parent');
      $crud->order_by('id_parent','asc');
      $crud->order_by('id_parent','asc');
      $crud->columns('menu');
      $where    = array('stato'=>'1');//not required
      $same_table   = true; //not required, the default is false
      $crud->callback_column('menu',array($this,'product_scale_callback'));
    
      $this->set_parent_relation($primary_id_field,$table_name,$parent_field,$title_field,$crud,$title_display_as,$relation_field_name,$where,$same_table);
      /* ------------------------------------------- */
    
      $output = $crud->render();
    
      $this->_example_output($output);
    }
   
    function product_scale_callback($value, $row)
    {
        //$products = $this->db->get('menuku');
        $query = $this->db->query("select * from menuku");
        foreach ($query->result() as $row)
        {
                 $id_parent = $row->id_parent;
                 echo $id_parent;
                if($id_parent === NULL)
                {
                return '-'.$value;
                } else {
                  $id_parent = $row->id;
                  $this->db->from('menuku');
                   $this->db->where('id_parent', $id_parent);
                   $result = $this->db->get();
                   foreach($result->result() as $row)
                       {
                        return '----'.$value;
                        $id_parent = $row->id;
                          $this->db->from('menuku');
                           $this->db->where('id_parent', $id_parent);
                           $result = $this->db->get();
                           foreach($result->result() as $row)
                        {
                            return '-------'.$value;
                            $id_parent = $row->id;
                              $this->db->from('menuku');
                               $this->db->where('id_parent', $id_parent);
                               $result = $this->db->get();
                               foreach($result->result() as $row)
                            {
                                return '----------'.$value;
                            }
                        }
                    }
                }
        }
    }
 

 

BUT the result is :

seven.png

 

between the main menu and sub ​​menu is displayed in not sequence and have not different spaces from the left.

could someone give me solution, please ?