You should not call your model from your view. Instead, try invoking the model and setting $data['groups'] before loading your views.
Also, do not repeat the results of the string in your model if you do not want it to appear on your page.
Controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Delivery_controller extends CI_Controller{ public function __construct() { parent::__construct(); $this->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->query('SELECT description FROM location'); return $query->result();
View:
<select class="form-control"> <?php foreach($groups as $row) { echo '<option value="'.$row->description.'">'.$row->description.'</option>'; } ?> </select>
source share