如何在codeigniter ..中使用excel_file更新数据库中的多个记录?

时间:2019-02-19 11:16:41

标签: excel upload codeigniter-3

虽然我试图用excel上传更新数据库中的多个记录,但给我一个错误。我已经用excel上传完成了在数据库中插入数据的操作,但是在更新时却创建了错误。

我的代码中有什么,请告诉我。

控制器代码:-

  public function family_head_info_import(){

     if (isset($_FILES["family_head"]["name"])) {
        $path = $_FILES["family_head"]["tmp_name"];
        $object = PHPExcel_IOFactory::load($path);
        foreach ($object->getWorksheetIterator() as $worksheet) {
            $highestRow = $worksheet->getHighestRow();
            $highestColumn = $worksheet->getHighestColumn();
            for ($row = 2; $row <= $highestRow; $row++) {
                //$branchid = $this->session->userdata('branch');
                $familyid = $worksheet->getCellByColumnAndRow(0, $row)->getValue();
                $headname1 = $worksheet->getCellByColumnAndRow(1, $row)->getValue();
                $hp1 = $worksheet->getCellByColumnAndRow(2, $row)->getValue();
                $type_relation = $worksheet->getCellByColumnAndRow(3, $row)->getValue();
                $email = $worksheet->getCellByColumnAndRow(4, $row)->getValue();
                $dob=$worksheet->getCellByColumnAndRow(5, $row)->getValue();
                $gender = $worksheet->getCellByColumnAndRow(6, $row)->getValue();





                $family_head[] = array(

                    //'family_id'   => $familyid,
                    'head1'         => $headname1,
                    'hp1'           => $hp1,
                    'type1'         => $type_relation,
                    'email1'        => $email,
                    'dob1'          => $dob,
                    'gender1'       => $gender
                );
            }

        }

        $this->excel_import_model->update_family_head($familyid,$family_head);


    }
}

型号:-

 public function update_family_head($fid,$data){
    $this->db->where("family_id",$fid);
    $this->db->update("family",$data);
}

错误:-

<h4>A PHP Error was encountered</h4>

严重性:通知

消息:数组到字符串的转换

文件名:database / DB_driver.php

行号:1524

<p>Backtrace:</p>










        <p style="margin-left:10px">
        File: /home/techz/public_html/myproject/application/controllers/Excel_import.php<br />
        Line: 111<br />
        Function: update            </p>

0 个答案:

没有答案