CSV文件从php导入到mysql

时间:2020-03-25 05:15:39

标签: file-import

我想尝试使用php&mysql导入.csv文件,但显示错误。看到我的代码:

function import()
{
    $this->load->library('csvimport');
    $file_data = $this->csvimport->get_array($_FILES["csv_file"]["tmp_name"]);
    //echo $file_data;
    foreach ($file_data as $row){
        //error_reporting(0);
        if($row["Check-in at"] > '0:00:00'){
            $date = date('Y-m-d',strtotime($row["Date"]));
            $duplicate = $this->attendance_model->getDuplicateVal($row["Employee No"],$date);
            //print_r($duplicate);
            if(!empty($duplicate)){
                $data = array();
                $data = array(
                    'signin_time' => $row["Check-in at"],
                    'signout_time' => $row["Check-out at"],
                    'working_hour' => $row["Work Duration"],
                    'absence' => $row["Absence Duration"],
                    'overtime' => $row["Overtime Duration"],
                    'status' => 'A',
                    'place' => 'office'
                );
                $this->attendance_model->bulk_Update($row["Employee No"],$date,$data);
           } else {
               $data = array();
               $data = array(
                   'emp_id' => $row["Employee No"],
                   'atten_date' => date('Y-m-d',strtotime($row["Date"])),
                   'signin_time' => $row["Check-in at"],
                   'signout_time' => $row["Check-out at"],
                   'working_hour' => $row["Work Duration"],
                   'absence' => $row["Absence Duration"],
                   'overtime' => $row["Overtime Duration"],
                   'status' => 'A',
                   'place' => 'office'
               ); 
               //echo count($data); 
               $this->attendance_model->Add_AttendanceData($data);          
           }
        } else {

        }
    }
    echo "successfully Updated"; 
}
}

错误是:

遇到PHP错误 严重程度:通知 消息:未定义的索引:在以下位置签到 文件名:controllers / Attendence.php 行号:241

回溯: 文件:..... / .. / .. / attendance.php 线:241 函数:error_handler

0 个答案:

没有答案