2013-08-29 3 views
0

배열에 대한 루프를 생성 한 후 다음에 업데이트 일괄 처리를 수행하지만 항목을 업데이트하려고 할 때마다 코드가 업데이트되지 않습니다. 나는 내 잘못이 어디에 있는지 눈치 채지 못한다. 쉬운 방법으로 업데이트 배치를 수행하려면 어떻게해야합니까?Codeigniter의 일괄 처리 오류 업데이트

/*THIS IS ALL ARRAY*/ 
$id = $this->input->post('idx'); 
$desc = $this->input->post('itemdesc'); 
$qty = $this->input->post('qty'); 
$price = $this->input->post('price'); 
$status = $this->input->post('status'); 

for($x = 0; $x < sizeof($id); $x++){ 

    $total[] = $price[$x] * $qty[$x]; 

    $updateArray[] = array(
     'poid' => $id[$x], 
     'item_desc' => $desc[$x], 
     'item_qty' => $qty[$x], 
     'price' => $price[$x], 
     'total' => $total[$x], 
     'status' => $status[$x] 
    ); 

    $this->db->update_batch('po_order_details',$updateArray, 'poid'); //I guess poid is my error but im not sure. I think my array won't find the correct id for where. 

    } 

가 여기 내 배열 샘플 출력입니다 : 난 당신이 날 도울 수 있기를 바랍니다 모든 사람을의

Array 
(
    [0] => Array 
     (
      [poid] => 5 
      [item_desc] => Yakisoba 
      [item_qty] => 15 
      [price] => 40,000.00 
      [total] => 600 
      [status] => ACTIVE 
     ) 

    [1] => Array 
     (
      [poid] => 6 
      [item_desc] => Laptop 
      [item_qty] => 5 
      [price] => 15,000.00 
      [total] => 75 
      [status] => ACTIVE 
     ) 

    [2] => Array 
     (
      [poid] => 7 
      [item_desc] => Speaker 
      [item_qty] => 3 
      [price] => 5,000.00 
      [total] => 15 
      [status] => ACTIVE 
     ) 

    [3] => Array 
     (
      [poid] => 8 
      [item_desc] => Mouse 
      [item_qty] => 5 
      [price] => 500.00 
      [total] => 2500 
      [status] => ACTIVE 
     ) 

    [4] => Array 
     (
      [poid] => 9 
      [item_desc] => Keyboard 
      [item_qty] => 5 
      [price] => 1,000.00 
      [total] => 5 
      [status] => ACTIVE 
     ) 

) 

여기 내 코드입니다.

+0

길이 :

$updateArray[] = array( 'poid' => "'".$id[$x]."'", 'item_desc' => "'".$desc[$x]."'", 'item_qty' => "'".$qty[$x]."'", 'price' => "'".$price[$x]."'", 'total' => "'".$total[$x]."'", 'status' => "'".$status[$x]."'" ); 
Red

+0

또한 루프 내부에서 업데이트하는 것처럼 보입니다. 루프를 통해 배열을 만들고 있으므로 루프가 완료된 후에 업데이트를 실행해야합니다. – Red

+0

업데이트 할 때마다 데이터를 업데이트 할 수 없습니다. – Jerielle

답변

0

이 좋아,하지만 내 프로세스는 오류가 무엇입니까

for ($x = 0; $x < sizeof($id); $x++) { 
    $total[] = $price[$x] * $qty[$x]; 
    $idvar = $desc[$x]; 

    $updateArray[] = array(
     'poid' => $id[$x], 'item_desc' => $desc[$x], 'item_qty' => $qty[$x], 
     'price' => $price[$x], 'total' => $total[$x], 'status' => $status[$x] 
    ); 
} 

for ($var = 0; $var < sizeof($updateArray); $var++) { 
    $idx = $updateArray[$var]['poid']; 

    $test = array(
     'item_desc' => $updateArray[$var]['item_desc'], 
     'item_qty' => $updateArray[$var]['item_qty'], 
     'item_price' => $updateArray[$var]['price'], 
     'total'  => $updateArray[$var]['total'], 
     'status'  => $updateArray[$var]['status'] 
    ); 

    $this->db->where('poid', $updateArray[$var]['poid']); 
    $this->db->update('po_order_details', $test); 
} 
1

배열의 각 값을 작은 따옴표로 묶은 다음 쿼리를 실행하십시오. 배열 값을 작은 따옴표로 묶는 코드를 편집했습니다. 그것을 시도하십시오. 다음은 수정 된 코드입니다. 내가 그것을했다

/*THIS IS ALL ARRAY*/ 
$id = $this->input->post('idx'); 
$desc = $this->input->post('itemdesc'); 
$qty = $this->input->post('qty'); 
$price = $this->input->post('price'); 
$status = $this->input->post('status'); 

for($x = 0; $x < sizeof($id); $x++){ 

$total[] = $price[$x] * $qty[$x]; 

$updateArray = array(
    //'poid' => $id[$x], 
    'item_desc' => $desc[$x], 
    'item_qty' => $qty[$x], 
    'price' => $price[$x], 
    'total' => $total[$x], 
    'status' => $status[$x] 
); 

$this->db->where('poid', $id[$x])->update('po_order_details', $updateArray); 
//$this->db->update_batch('po_order_details',$updateArray, 'poid'); //I guess poid is my error but im not sure. I think my array won't find the correct id for where. 

} 
+0

감사합니다. 나는 그것을 시도 할 것입니다. – Jerielle

1

도움을 당신이 될 수도 같은 시도? 어느 것이 업데이트되지 않습니까? `DB_DEBUG`를`TRUE`로 설정하고 실제 쿼리를 검사하십시오.
+0

응답 해 주셔서 감사합니다. 나는 이미 그것을 풀었다. 그러나 나는 당신의 코드를 시도 할 것이다. 그것이 맞는 것 같습니다. – Jerielle