I have data on db_temporary
here I will update based on id_service
, but why doesn’t the update work?
public function updateUpload() { $db = $this->M_order->db_temporary_service(); //db_temporary $data = array(); foreach($db AS $key => $val){ $data[] = array( "id_service" => $_POST['id_service'][$key], "id_destination" => $_POST['id_destination'][$key], "id_sub_destination" => $_POST['id_sub_destination'][$key], "charges_order" => $_POST['charges_order'][$key], "weight_order" => $_POST['weight_order'][$key], "jenis_service" => $_POST['jenis_service'][$key], "service_order" => $_POST['service_order'][$key], "charges_order" => $_POST['charges_order'][$key], ); echo '<pre>', print_r($data); //update to db_service where id_service $this->db->update_batch('service', $data, 'id_service'); redirect('backend/.....'); } }
Advertisement
Answer
The data doesn’t seem to be updated because you’ve used update_batch
as well as redirect
inside foreach
loop, I’m writing the rectified code below, comments are mentioned wherever necessary. See if it resolves your issue.
public function updateUpload(){ $db = $this->M_order->db_temporary_service(); //db_temporary $data = array(); foreach($db AS $key => $val){ $data[] = array( "id_service" => $_POST['id_service'][$key], "id_destination" => $_POST['id_destination'][$key], "id_sub_destination" => $_POST['id_sub_destination'][$key], "charges_order" => $_POST['charges_order'][$key], "weight_order" => $_POST['weight_order'][$key], "jenis_service" => $_POST['jenis_service'][$key], "service_order" => $_POST['service_order'][$key], "charges_order" => $_POST['charges_order'][$key], ); } // echo '<pre>', print_r($data); // all the data should be here $this->db->update_batch('service', $data, 'id_service'); // update the table with all the data redirect('backend/.....'); }