CodeIgniter:从excel intp现有的MySQL数据库上传数据

我想从Excel中上传数据到我的数据库两次(从单独的Excel文件)

像这样,我的桌子:

id | name | address | account | note 

这是第一个excel数据:

 id | name | address 

第二个Excel

 account | note 

这是我的控制者:

 public function upload(){ $this->load->helper('file'); $fileName = time().$_FILES['file']['name']; $config['upload_path'] = FCPATH.'assets/'; //buat folder dengan nama assets di root folder $config['file_name'] = $fileName; $config['allowed_types'] = 'xls|xlsx|csv'; $config['max_size'] = 10000; $this->load->library('upload'); $this->upload->initialize($config); if(! $this->upload->do_upload('file') ) $this->upload->display_errors(); $media = $this->upload->data('file'); $inputFileName = $this->upload->data('full_path'); //'.assets/'.$media['file_name']; try { $inputFileType = IOFactory::identify($inputFileName); $objReader = IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($inputFileName); } catch(Exception $e) { die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage()); } $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn(); for ($row = 2; $row <= $highestRow; $row++){ // Read a row of data into an array $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE); $data= array( "name"=> $rowData[0][1], "address"=> $rowData[0][2] ); $insert = $this->db->insert("info",$data); delete_files($config['file_path'],TRUE); } } 

我试图做第二个相同的代码,但我不能将数据插入到现有的行,它总是插入到新的行。 喜欢这个:

 id | name | address | account | note 1 a aa 2 b bb 3 1 a 4 2 bb 

任何人都可以帮助/给我想法如何join他们? 任何帮助,将不胜感激! 谢谢!

第二个Excel数据是这样的

 id | account | note 

并更新account | note account | note与ID的列

 <?php 

如果(isset($ _ POST [ “导入”])){

  $filename=$_FILES["file"]["tmp_name"]; if($_FILES["file"]["size"] > 0) { $file = fopen($filename, "r"); while (($getData = fgetcsv($file, 10000, ",")) !== FALSE) { $sql = "INSERT into table (name,address) values ('".$getData[0]."','".$getData[1]."')"; $result = mysqli_query($con, $sql); if(!isset($result)) { echo "<script type=\"text/javascript\"> alert(\"Invalid File:Please Upload CSV File.\"); window.location = \"index.php\" </script>"; } else { echo "<script type=\"text/javascript\"> alert(\"CSV File has been successfully Imported.\"); window.location = \"index.php\" </script>"; } } fclose($file); } } 

?>