Hallo! Selamat Datang di Marketplace produk digital, Freelancer terbaik di indonesia (68414 Members, 793 Products, 5353 Topic, 13045 Comments)

Cara buat perintah update_batch pada codeigniter

Dibuat
Login Terakhir 3 Tahun lalu,
Telah Dilihat 5237 Kali
Agus Ramdhanni Mengatakan : Sultan Account
  1. Assalamualaikum Warahmatullahi Wabarakatuh...
  2. selamat pagi pak, saya lagi bikin perintah update_batch dengan model seperti ini :
  3.  
  4. public function update_multi($table, $data, $where){
  5. return $this->db->update_batch($table, $data, $where);
  6. }
  7.  
  8. dengan controller :
  9.  
  10. function ubah_usulan_kegiatan(){
  11. cek_session_akses('ubah_usulan_kegiatan',$this->session->id_session);
  12. $a = $this->uri->segment(3);
  13.  
  14. if (isset($_POST['submit'])){
  15. $data2 = array(
  16. 'kd_usulan'=>$this->db->escape_str($this->input->post('a')),
  17. 'x'=> $this->db->escape_str($this->input->post('x[]')),
  18. 'y'=> $this->db->escape_str($this->input->post('y[]')),
  19. 'username'=>$this->session->username);
  20. $where2 = array('kd_usulan' => $this->input->post('a'));
  21. $new_values = array();
  22.  
  23. for($x = 0, $size = count($data2['x']); $x < $size; $x++) {
  24. foreach($data2 as $key => &$value) {
  25. if(!is_array($value) || empty($value)) {
  26. $new_values[$x][$key] = $value;
  27. } else {
  28. $new_values[$x][$key] = array_shift($value);
  29. }
  30. }
  31.  
  32. }
  33. $this->model_app->update_multi('ref_tbl_kordinat',$new_values,$where2);
  34. redirect('administrator/usulan');
  35. }else{
  36. if($this->session->level=='admin'){
  37. $proses = $this->model_app->edit('tbl_usulan', array('no_urut' => $a))->row_array();
  38. $proses31 = $this->model_app->view_ordering('ref_tbl_kordinat','kd_usulan','DESC');
  39. }else{
  40. $proses = $this->model_app->edit('tbl_usulan', array('no_urut' => $a, 'username'=>$this->session->username))->row_array();
  41. $proses31 = $this->model_app->view_ordering('ref_tbl_kordinat','kd_usulan','DESC');
  42. }
  43. $data = array('rows' => $proses,'proses31'=>$proses31);
  44. $this->template->load('administrator/template','administrator/form_usulan/view_edit_usulan',$data);
  45. }
  46. }
  47.  
  48. dengan output errornya seperti ini
  49.  
  50. Array ( [0] => Array ( [kd_usulan] => 1 [x] => 1.00 [y] => 2.00 [username] => admin ) [1] => Array ( [kd_usulan] => 1 [x] => 1.00 [y] => 2.00 [username] => admin ) [2] => Array ( [kd_usulan] => 1 [x] => 1.00 [y] => 2.00 [username] => admin ) )
  51. A Database Error Occurred
  52.  
  53. One or more rows submitted for batch updating is missing the specified index.
  54.  
  55. Filename: C:/xampp/htdocs/febri/system/database/DB_query_builder.php
  56.  
  57. Line Number: 2028
  58.  
  59. mohon bantuannya....gan
  60.  
  61.  

Ada 2 Jawaban

Bukhori Muslim
commented on 25 Okt 2019 08:43:31
  1. Assalamualaikum,.. dilihat dari pesan errornya, sepertinya id key yang dituju tidak ditemukan,
  2. berikut contoh salah satu cara update_batch yang pernah saya share juga di forum ini :
  3. <form action='' method='GET'>
  4. <select multiple class="form-control" name="product[]" data-width="100%" data-live-search="true" multiple required>
  5. <option value="1">1</option>
  6. <option value="2">2</option>
  7. <option value="3">3</option>
  8. <option value="4">4</option>
  9. <option value="5">5</option>
  10. </select>
  11. <input class="form-control" type="text" name="days" min="0" placeholder="Days" />
  12. <input type='submit' value='Proses'>
  13. </form>
  14.  
  15. <?php
  16. for ($i=0; $i < count($_GET['product']); $i++) {
  17. echo $_GET['product'][$i].' = '.$_GET['days'].'<br>';
  18. }
  19. ?>
Agus Ramdhanni
commented on 04 Nov 2019 09:18:42
  1. Assalamualaikum,.. admin saya sudah menemukan caranya
  2.  
  3.  
  4. $mod=count($this->input->post('x'));
  5. $mod1= $this->model_app->nomor_urut_kordinat();
  6. $mod2=$this->input->post('kdusulan');
  7. $mod3=$this->input->post('x');
  8. $mod4=$this->input->post('y');
  9. $mod5=$this->session->username;
  10.  
  11. for($i = 0; $i<$mod; $i++){
  12.  
  13. $entries[] = array(
  14. 'no_urut'=>$mod1+$i,
  15. 'kd_usulan'=>$mod2,
  16. 'x'=>$mod3[$i],
  17. 'y'=>$mod4[$i],
  18. 'username'=>$mod5
  19. );
  20. }
  21. $this->db->insert_batch('ref_tbl_kordinat', $entries);
  22. mohon koreksinya
Maaf, Untuk Memberikan Komentar Anda Harus Login !!!

Online