Codeigniter select option view records from mysql

Viewed 34

I've got some troubles with loading db data to an select option form. Records are not showing and I don't know where is a problem.. I need to view 'name' from 'location_cities' table in db.

Controller:

public function edit_product($id)
    {
$data['product_location'] = $this->product_model->get_product_location();
$this->load->view('dashboard/includes/_header', $data);
        $this->load->view('dashboard/product/edit_product', $data);
        $this->load->view('dashboard/includes/_footer');
    }

Model:

function get_product_location()
    {
      $this->db->join('location_cities');
      $this->db->select('location_cities.*');
      $query = $this->db->get('location_cities');
      return $query->result(); 
    }

View:

  <select name="product_city" class="select2 form-control">
    <?php
 foreach ($product_location as $row): ?>
 <option value="<?= $row->name; ?>"><?= $row->name; ?></option> 
  <?php endforeach; ?>
</select>

I would much appreciate your tips how to fix this. Kind regards, Krzysztof

1 Answers

in your controller get reponse is not work unless you dont get it...

$this->product_model->get_product_location()->result_array();
Related