没有使用多个复选框获取正确的主ID进行更新 - codeigniter

时间:2014-08-04 03:31:49

标签: javascript html codeigniter

我有多个由foreach循环生成的复选框。我的问题是关于更新已检查的行。

HTML结果:

<tr>
<td><input type = "text" name = "item_id[]" id = "item_id" value ="202" >       </td>
<td>ITEM 1 A FOR QUOTAION</td>
<td>123</td>
<td><input type = "checkbox" name = "JobStatus[]" value = "quotation" ></td>
<td><input type = "checkbox" name = "JobStatus[]" value = "job order" ></td>                                     
</tr>

<tr>
<td><input type = "text" name = "item_id[]" id = "item_id" value ="203" ></td>
<td>ITEM 2 FOR JOB ORDER</td>
<td><input type = "checkbox" name = "JobStatus[]" value = "quotation" ></td>
<td><input type = "checkbox" name = "JobStatus[]" value = "job order" ></td>                                     
                             </tr>

<tr>
<td><input type = "text" name = "item_id[]" id = "item_id" value ="204" ></td>
<td>ITEM 3 B FOR QUOTATION</td>
<td>2323</td>
<td><input type = "checkbox" name = "JobStatus[]" value = "quotation" ></td>
<td><input type = "checkbox" name = "JobStatus[]" value = "job order" ></td>                                     
</tr>

查看

<?php foreach($item_list as $item2):?>        
 <tr>
 <td><input type = "text" name = "item_id[]" id = "item_id" value ="<?php echo $item2->item_id ?>" ></td>
 <td><?php echo $item2->item_desc?></td>
 <td><?php echo $item2->serial_num ?></td>
 <td><input type = "checkbox" name = "JobStatus[]" value = "quotation" ></td>
 <td><input type = "checkbox" name = "JobStatus[]" value = "job order" ></td>                                    
 </tr>
 <?php endforeach; ?>

位指示

 public function do_update_item_status()
 {
   $this->load->model("crud_model");
   if($this->session->userdata('logged_in'))
   {
   $session_data = $this->session->userdata('logged_in');
   $data['username'] = $session_data['username'];

   $item_id = $this->input->post('item_id', TRUE);
   $JobStatus =  $this->input->post('JobStatus', TRUE);

   if ($this->input->post('submit')) 
   {
     $data = $this->crud_model->do_update_item_status_model($item_id);
   }  

    $this->load->view('scaffolds/header', $data);
    $this->load->view('pages/update_item_status_individual', $data);
    $this->load->view('scaffolds/footer-update', $data);   
   }
 }

MODEL

 function do_update_item_status_model($item_id)
 {  
  $JobStatus =  $this->input->post('JobStatus');
  $company_id = $this->input->post('company_id');
  $create_date = $this->input->post('create_date');
  $status = $this->input->post('status');

  $cal_date= $create_date;
  $format = strtotime($cal_date);
  $mysql_date=date('Y-m-d H:i:s', $format);
  $row_count = count($JobStatus);

  for($i=0;$i<$row_count;$i++)
  {
     $rows = array(   
      'JobStatus'=>$JobStatus[$i]   
       );    
     $this->db->where('item_id',$item_id[$i]);
     $this->db->update('item', $rows);  
   }
 }

这是有效但我的问题是当我检查item_id = 204时它只更新数据库中的第一行请帮助谢谢

0 个答案:

没有答案