2016-11-05 2 views
0

Codeigniter의 새로운 학습자를 도울 수 있습니까? 어떤 이유로 내 양식 드롭 다운 내게 입력 -> 게시물로 인덱스를 제공하고 있습니다. 텍스트를 선택하면됩니다.양식 드롭 다운에서 텍스트가 아닌 색인을 제공합니다.

모델

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; 
     } 

보기 대신 "텍스트 값"의

<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> 

컨트롤러

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 to inventory.</div>'); 
      redirect('commissary/added_to_inventory'); 
     } 
    } 

양식 드롭 다운에서 색인 1 또는 2 또는 3 또는 4 또는 5 등을 얻습니다. 감사합니다.

답변

0

즉, <select> 옵션이 작동하는 경우 - 선택 옵션 인 value이 반환됩니다.

텍스트를 원할 경우 $item_names을 다르게 설정하고 index을 텍스트와 동일하게 설정해야합니다. 모델에서 약간의 구조 조정만으로 손쉽게 수행 할 수 있습니다.

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 as $item) 
    { 
    $item_names[$item->item_name] = $item->item_name; 
    } 

    return $item_names; 
} 
관련 문제