PHPExcel将数据值上传到它插入的数据库但它插入了太多且重复的值...我不知道我错在哪里我认为在我的逻辑中我的循环可以任何人帮助实现我想要输出
我想实现的是第一次搜索列的第一行的值然后如果列的第一行相等则该列的整行必须上传到对应于表的理想列的数据库中数据库
先谢谢你们
对不起我的英文
$inputFileName = $_FILES["file"]["tmp_name"];
try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
} catch(Exception $e) {
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}
$a = "emp_no";
$b = "dep_no";
$c = "hmo_no";
$d = "lastname";
$e = "firstname";
$f = "middlename";
$g = "gender";
$h = "dob";
$emp_no = "";
$dep_no = "";
$hmo_no = "";
$lname = "";
$fname = "";
$mname = "";
$gender = "";
$dob = "";
$objWorksheet = $objPHPExcel->getActiveSheet();
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
for ($row=2; $row < $highestRow; $row++) {
for ($col = 0; $col <= $highestColumnIndex; ++$col) {
$extitle = $objWorksheet->getCellByColumnAndRow($col, 1)->getValue();
if($extitle == $a){
$data = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
$emp_no = $data;
}
if($extitle == $b){
$data = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
$dep_no = $data;
}
if($extitle == $c){
$data = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
$hmo_no = $data;
}
if($extitle == $d){
$data = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
$lname = $data;
}
if($extitle == $e){
$data = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
$fname = $data;
}
if($extitle == $f){
$data = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
$mname = $data;
}
if($extitle == $g){
$data = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
$gender = $data;
}
if($extitle == $h){
$data = $objWorksheet->getCellByColumnAndRow($col, $row);
if(PHPExcel_Shared_Date::isDateTime($data)){
$cellValue = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
$dateValue = PHPExcel_Shared_Date::ExcelToPHP($cellValue);
$dob = date('M-d-Y',$dateValue);
}else{
$dob = "NULL";
}
}
mysql_query ("insert into membertable (emp_no,dep_no,hmo_no,lastname,firstname,middlename,gender,dob) VALUES ('".$emp_no."','".$dep_no."','".$hmo_no."','".$lname."','".$fname."','".$mname."','".$gender."','".$dob."');");
}
//
}