Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在codeigniter上多次更新数据_Php_Mysql_Codeigniter - Fatal编程技术网

Php 如何在codeigniter上多次更新数据

Php 如何在codeigniter上多次更新数据,php,mysql,codeigniter,Php,Mysql,Codeigniter,如何将自动增量值设置为post。 在这里,我成功地插入了两个表,我在插入后创建了一个条件,然后更新了数据。 我有两个表,第一个是“服务”表,第二个是“客户地址” 客户地址表,id地址为自动递增 在向两个表中插入数据时,我希望在customer\u address表中获取值id\u address。要更新到“服务”表 public function import () { include APPPATH. 'third_party/PHPExcel/PHPExcel.php'

如何将自动增量值设置为post。 在这里,我成功地插入了两个表,我在插入后创建了一个条件,然后更新了数据。 我有两个表,第一个是“服务”表,第二个是“客户地址”

客户地址表,id地址为自动递增

在向两个表中插入数据时,我希望在customer\u address表中获取值id\u address。要更新到“服务”表

 public function import () {
     include APPPATH.
     'third_party/PHPExcel/PHPExcel.php';
     $excelreader = new PHPExcel_Reader_Excel2007();
     $loadexcel = $excelreader-> load('excel/'.$this-> filename.
         '.xlsx'); //here I am loading data from an excel file for import
     $sheet = $loadexcel->getActiveSheet()->toArray(null, true, true, true);
     $data = array();
     $numrow = 1;
     foreach($sheet as $row) {

         $a['acak'] = $this-> M_order-> bikin_kode();
         $resi = $a['acak'];
         $key1 = $this-> M_order-> db_cek($row['C']);
         $origin = $key1['id_origin'];
         if ($numrow > 1) {
             array_push($data, array(
                 'tracking_number' => $resi,
                 'id_cs' => $row['B'],
                 'id_origin' => $origin,
                 'id_muat' => $row['D'],
             ));

             $datax = array(
                 //'id_alamat'           => this autoincrement
                 'id_cs' => $row['AM'],
                 'nama' => $row['AN'],
             );
             $this->db-> insert('customer_address', $datax);

             // this update data to table service //
             //here I am looping, to retrieve the address_id which was just at POST,
             $isi = $this->db-> select('id_alamat')-> from('customer_address')->where('id_kota', $kot)->get()-> result();
             foreach($sheet as $value) {
                 $hsl = array(
                     'id_muat' => $value - > id_alamat,
                 );

                 $this->db->update('service', $hsl);
             }
         }
         $numrow++;
     }
     $this->M_order->insert_multiple($data); //to table service
 }

当我更新“服务”表时,我更新了所有内容。如何仅根据数据输入进行更新?

您必须将id\u alamat从视图发送到控制器,并生成唯一代码,而不仅仅是使用自动增量。 例如:

   public function import () {
         include APPPATH.
         'third_party/PHPExcel/PHPExcel.php';
         $excelreader = new PHPExcel_Reader_Excel2007();
         $loadexcel = $excelreader-> load('excel/'.$this-> filename.
             '.xlsx'); //here I am loading data from an excel file for import
         $sheet = $loadexcel->getActiveSheet()->toArray(null, true, true, true);
         $data = array();
         $numrow = 1;
         foreach($sheet as $row) {

             $a['acak'] = $this-> M_order-> bikin_kode();
             $resi = $a['acak'];
             $key1 = $this-> M_order-> db_cek($row['C']);
             $origin = $key1['id_origin'];
             if ($numrow > 1) {
                 array_push($data, array(
                     'tracking_number' => $resi,
                     'id_cs' => $row['B'],
                     'id_origin' => $origin,
                     'id_muat' => $row['D'],
                 ));

                 $datax = array(
                     'id_alamat' => $row['id_alamat'],
                     'id_cs' => $row['AM'],
                     'nama' => $row['AN'],
                 );
                 $this->db-> insert('customer_address', $datax);

                 // this update data to table service //
                 //here I am looping, to retrieve the address_id which was just at POST,
                 $isi = $this->db->select('id_alamat')->from('customer_address')->where('id_kota', $kot)->get()-> result();
                //change $sheet to $isi   
                 foreach($isi as $value) {
                     $hsl = array(
                         'id_muat' => $value->id_alamat,
                     );

                     $this->db->update('service', $hsl);
                 }
             }
             $numrow++;
         }
         $this->M_order->insert_multiple($data); //to table service
     }