如何将数组元素与数据库数据进行比较

时间:2018-07-06 08:09:02

标签: php arrays excel phpspreadsheet

我有一个导入页面,用户可以在其中导入将存储在数据库中的Excel页面。在这里,我需要确保Excel中的数据不重复,因此我需要对照DB数据检查Excel行数据。我使用了https://github.com/nuovo/spreadsheet-reader插件。

但是Excel的读取输出类似于连续数组:

array(1) {
  [0]=>
  string(3) "122"
}

array(2) {
  [0]=>
  string(3) "123"
}

如何摆脱这种格式的数组?我无法将其与从数据库中获取的数据进行比较。

代码:https://plnkr.co/edit/UNFkO9Z6s6MNqyUeixio?p=catalogue

$Reader = new SpreadsheetReader($targetPath);

$sql_function = "select * from function";
$result_function = mysqli_query($con, $sql_function);

while($row1 = mysqli_fetch_array($result_function)){
     $tot_units[] = $row1['total_units'];
     $tot_secs[]  = $row1['total_secs'];
     $start_time[] = $row1['start_time'];
     $end_time[]  = $row1['end_time'];
}

foreach ($Reader as $getData){
        $secs = strtotime($getData[5]) - strtotime('TODAY');
        for($k=0;$k<count($tot_units);$k++){
            if(($getData[4]==$tot_units[$k]) && 
                ($getData[5]==$tot_secs[$k]) && 
                ($getData[6]==$start_time[$k]) && 
                ($getData[7]==$end_time[$k])){
                    echo "test"; 
                    break;
            }
            else{
               $sql = "INSERT into function (function_id, function_code, operator_id, sup_id, total_units, total_secs, performed_on_date, start_time, end_time, flag) values ('".$getData[0]."','".$getData[1]."','".$getData[2]."','".$getData[3]."','".$getData[4]."','".$secs."','".date('Y-m-d',strtotime($getData[6]))."','".$getData[7]."','".$getData[8]."','".$getData[9]."')";
               $result = mysqli_query($con, $sql);
            }
        }
}

0 个答案:

没有答案
相关问题