display data from database to dropdown CodeIgniter

后端 未结 6 1473
星月不相逢
星月不相逢 2020-12-03 08:54

I\'m having difficulty with display data from the db to dropdown.

This is what I have tried:

Model.php

        public funct         


        
6条回答
  •  旧时难觅i
    2020-12-03 09:27

    You should not be calling your model from your view. Instead try calling you model and setting $data['groups'] before you load your views.

    Also do not echo the row results in your model unless you want it displayed on your page.

    Controller:

    load->model('delivery_model');
    
        }
        public function index()
        {
    
            $data['title']= 'Warehouse - Delivery';
            $data['groups'] = $this->delivery_model->getAllGroups();
            $this->load->view('include/header',$data);
            $this->load->view('include/navbar',$data);
            $this->load->view('delivery_view', $data);
            $this->load->view('include/sidebar',$data);
            $this->load->view('include/footer',$data);
    
        }
    
    
    }
    

    Model:

        public function __construct()
        {
            parent::__construct();
        }
    
        function getAllGroups()
        {
            /*
            $query = $this->db->get('location');
    
            foreach ($query->result() as $row)
            {
                echo $row->description;
            }*/
    
            $query = $this->db->query('SELECT description FROM location');
    
    
            return $query->result();
    
            //echo 'Total Results: ' . $query->num_rows();
        }
    

    View:

           
    

提交回复
热议问题