【发布时间】:2017-02-03 07:19:56
【问题描述】:
这里我在 php 中使用 xls 文件阅读器,它工作正常,我已经制作了一个逻辑,xls 文件我正在获取徽章编号(4565)和月份(01-2017)现在我想检查徽章编号并且月份已经存在数据或不存在,假设数据是exixts意味着我不应该允许插入新记录,假设不退出意味着我想允许插入新记录,该怎么做,我因为xls表而感到困惑。
<?php
include 'excel_reader.php';// include the class
$groupfile ='test.xls';
$excel = new PhpExcelReader;
$excel->read($groupfile);
function sheetData($sheet) {
$result = '';
$row = 2;
while($row <= $sheet['numRows']) {
$id = isset($sheet['cells'][$row][1]) ? $sheet['cells'][$row][1] : '';
$loan_month = isset($sheet['cells'][$row][2]) ? $sheet['cells'][$row][2] : '';
$badge_number = isset($sheet['cells'][$row][3]) ? $sheet['cells'][$row][3] : '';
$name = isset($sheet['cells'][$row][4]) ? $sheet['cells'][$row][4] : '';
$pf_amount = isset($sheet['cells'][$row][5]) ? $sheet['cells'][$row][5] : '';
$loan_amount = isset($sheet['cells'][$row][6]) ? $sheet['cells'][$row][6] : '';
$date_format=date('d/m/Y');
$status=0;
$explode_date=explode("/",$loan_month) ;
$month = $explode_date[1].'-'.$explode_date[2] ;
$sql = mysql_query("INSERT INTO loan_history(pf_month,badge_number,first_name,pf_amount,loan_amount,reg_date,status)VALUES('$month','$badge_number','$name','$pf_amount','$loan_amount','$date_format','$status')");
if($sql){
echo "success" ;
}else{
echo mysql_error();
}
$row++;
}
}
$nr_sheets = count($excel->sheets);
for($i=0; $i<$nr_sheets; $i++) {
sheetData($excel->sheets[$i]);
}
?>
【问题讨论】:
-
那么数据库中有一个表,其中“badge_number”和“month_year”是主要列?
-
我的要求是相同的月份和相同的 badge_number 然后我只想停止,假设相同的 badge_number 但月份不同意味着我想插入值怎么做
标签: php filereader phpexcelreader