在codeigniter中的update_batch中将id作为数组获取

时间:2018-05-29 05:22:44

标签: php codeigniter

我在批量更新时收到Id as Array。无法将数据更新到现有数据表。请帮帮我

我的错误信息如下所示 Error Message as Image Format

控制器



In [8]: import pdfbox
   ...: p = pdfbox.PDFBox()
   ...: 

In [9]: p
Out[9]: <pdfbox.PDFBox at 0x1046254e0>
&#13;
&#13;
&#13;

查看

&#13;
&#13;
public function update() 
{

$sID   = $this->input->post('test_id[]');
$sAmt  = $this->input->post('test_priceUpdt[]');
$sOfficeId = $this->input->post('fran_office_id');
$edited_test = array();
for ($i=0; $i < sizeof($sID); $i++)
		{
			if(!empty($sID[$i])) 
			$edited_test[$i] = array(
				'test_id' => $sID[$i],
				'test_priceUpdt' => $sAmt[$i],
				'fran_office_id' => $sOfficeId
			);
}

$edited_test = json_encode($edited_test); 
$data['franchise_tst_pkg'] = (object)$postData = array (
				array(
					'test_id' => $sID,
					't_franchise_price' => $edited_test
				)
			
 ); 
 if ($this->form_validation->run() === true) {
 $this->franchise_price_model->batchTestupdate($postData))
 }

}
&#13;
&#13;
&#13;

模态

&#13;
&#13;
<tr>
  <td>
    <input type="text" name="test_name[]" class="form-control" placeholder="" value="<?php echo $subject->test_name; ?>" disabled>
    <input type="hidden" name="test_id[]" class="form-control" placeholder="" value="<?php echo $subject->test_id; ?>">
  </td>
  <td>
    <input type="text" name="test_price[]" class="form-control" placeholder="" value="<?php echo $subject->test_price; ?>" disabled>
  </td>
  <td>
    <input type="text" name="test_priceUpdt[]" class="form-control" placeholder="" value="<?php echo $subject->test_price; ?>" id="test_priceEdt">
  </td>
</tr>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

update_batch(..)函数中的第二个参数结构错误。

更改:

$data['franchise_tst_pkg'] = (object)$postData = array (
                array(
                    'test_id' => $sID,
                    't_franchise_price' => $edited_test
                )

$postData = array();
if(is_array($sID)){
    foreach($sID as $k=>$v){
        $postData[] = array(
            'test_id' => $v,
            't_franchise_price' => $edited_test
        );
    }
}
$data['franchise_tst_pkg'] = (object)$postData;

答案 1 :(得分:0)

您可以将模型更改为:

public function batchTestupdate($data = []) 
{ $this->db
        ->update_batch($this->table_test, explode(',', $data) , 'test_id');
}