codeigniter - Form dropdown is giving me index and not the text -


can out new learner of codeigniter? reason form dropdown giving me index input->post. need text selected.

model

function get_items(){         $this->db->select('item_name');         $this->db->from('commissary_items');         $query=$this->db->get();         $result=$query->result();              $item_names=array('-select-');              for($i=0;$i<count($result);$i++){                 array_push($item_names,$result[$i]->item_name);             }              return $item_names;         } 

view

 <div class="form-group">                 <div class="row colbox">                 <div class="col-lg-4 col-sm-4">                     <label for="item_name" class="control-label">item</label>                 </div>                 <div class="col-lg-8 col-sm-8">                     <?php                     $attributes = 'class = "form-control" id = "item_name"';                     echo form_dropdown('item_name',$item_name,set_value('item_name'),$attributes);?>                     <span class="text-danger"><?php echo form_error('item_name'); ?></span>                 </div>                 </div>             </div> 

controller

public function new_inventory(){         $data['item_name']=$this->commissary_model->get_items();          $this->form_validation->set_rules('date_added','date added','required');         $this->form_validation->set_rules('item_name','item name','callback_combo_check');         $this->form_validation->set_rules('quantity','quantity','required');         $this->form_validation->set_rules('amount','amount','required|numeric');         $this->form_validation->set_rules('username','user name');          if($this->form_validation->run()==false){             // $data="";             $this->load->view('new_inventory_view',$data);         }else{             $data=array(                     'date_added'=>@date('y-m-d',@strtotime($this->input->post('date_added'))),                     'item_name'=>$this->input->post('item_name'),                     'quantity'=>$this->input->post('quantity'),                     'amount'=>$this->input->post('amount'),                     'username'=>$this->session->userdata('username')                 );             $this->db->insert('add_inventory',$data);             $this->session->set_flashdata('msg','<div class="alert alert-success text-center">item added inventory.</div>');             redirect('commissary/added_to_inventory');         }     } 

instead of "text value" inside form dropdown, index 1 or 2 or 3 or 4 or 5 etc.... thank you.

that how <select> options work - value of select option returned.

if want text have setup $item_names differently , have index same text. accomplished little restructuring in model.

function get_items() {   $this->db->select('item_name');   $this->db->from('commissary_items');   $query = $this->db->get();   $result = $query->result();    $item_names = array();    foreach($result $item)   {     $item_names[$item->item_name] = $item->item_name;   }    return $item_names; } 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -