Hi i am trying to fetch data from database into my dropdown menu in codeigniter, but havind error of 'undefined variable: unit_name' .
this is my model file
`public function get_unit_value() {
$result = $this ->db ->select('id, unit_name') -> get('units') -> result_array();
$unit_name = array();
foreach($result as $r) {
$unit_name[$r['id']] = $r['unit_name'];
}
$unit_name[''] = 'Select unit...';
return $unit_name;
}`
this is my controller
`public function unit(){
$this->load->database();
$this->load->model('client_model');
$data['unit_name'] = $this ->client_model-> get_unit_value();
$this -> load -> view('add_quote', $data);
}`
this s my view file
<div class="panel panel-default"> <div class="panel-heading">The form</div> <div class="panel-body"> <!--dropdown input--> <?php echo form_dropdown('unit_name',$data['unit_name'], '', 'class="form-control"');?> <br> <br> <button type="submit" class="btn btn-info">Submit</button> </div>