我有一个看起来像这样的 .csv 文件...
Name AC-No. Time State Exception Operation
Johnny Starks Depp 1220 4/12/2013 12:45:18 AM Check In OK
Johnny Starks Depp 1220 4/12/2013 5:46:58 AM Out Out
Johnny Starks Depp 1220 4/12/2013 6:22:41 AM Out Back Out
Johnny Starks Depp 1220 4/12/2013 10:42:17 AM Check Out Repeat
Johnny Starks Depp 1220 4/12/2013 10:42:19 AM Check Out OK
我已经可以把它上传到我的数据库了。我的问题是,它显示在表格中的结果。在 mysql 数据库中,我有一个包含列(Name、ACNo.、Date、CheckIn、Breakout、Breakin、CheckOut)的 TABLE。我想要发生的事情是我做错了.. .csv 文件中具有相同DATE的记录(显示在时间列中)将与签入、中断、表中的 BreakIn 和 CheckOut 不会产生多条记录。像这样..
Name |ACNo | Date | CheckIn | Breakout | Breakin | Checkout
| | | | | |
Johnny Starks Depp|1220 | 4/12/2013 | 12:45:18 AM | 5:46:58 AM | 6:22:41 AM | 10:42:19 AM
现在..我已经做了上面我想在表格中发生的示例但是...当我检查表格时,是的,它每行有不同的日期,但是(签入,突破,突破,结账)中的时间是错误的. 错误,因为例如 DATE 4/12/2013 中的时间记录在 DATE 4/13/2013 中。我使用的代码有什么问题?或者我还有什么办法可以做到这一点?这些是我的代码:
<?php
$conn = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("dtrlogs",$conn);
$datehere ="";
if(isset($_POST['Submit']))
{
$file = $_FILES['file']['tmp_name'];
if($file == "")
{
?>
<script type="text/javascript">
alert('No File Selected!');
</script>
<?php
}
else
{
$handle = fopen($file,"r");
while(($fileop = fgetcsv($handle,1000,";")) !==false)
{
$Name = $fileop[0];
$ACNo = $fileop[1];
$Time = $fileop[2];
$State = $fileop[3];
$NewState = $fileop[4];
$Exception = $fileop[5];
$Operation = $fileop[6];
//i separated time/date in the Column TIME in the .csv file
$date = date('m/d/Y', strtotime($Time));
$hours = date('H:i:s A', strtotime($Time));
//this is what i used to prevent multiple dates
if($datehere != $date) {
$datehere = $date;
}
else{
$date = "";
}
//this is to insert the name and acno to the other table.
//(this is for the lists of employee)
$sql=mysql_query("SELECT * FROM employee Where ACNo = '$ACNo'");
$row=mysql_fetch_array($sql);
if($row == 0) {
$sql1 = mysql_query("INSERT INTO employee(ACNo, Name) VALUES('$ACNo','$Name')");
}
//Inserts record if Date is not yet recorded and if already has just updates
//the row's column (Checkin, breakout, breakin and Checkout)
//with its correct time according to the date
$query = mysql_query("SELECT * FROM dtrs Where ACNo = '$ACNo' AND Date = '$date'");
$rows = mysql_fetch_array($query);
if($rows == 0) {
$sql2 = mysql_query("INSERT INTO dtrs(Name, ACNo, Date, CheckIn, BreakOut,
BreakIn,CheckOut)
VALUES('$Name','$ACNo','$date','$CheckIn','$Breakout','$Breakin','$Checkout')");
}
else{
$sql2 = mysql_query("Update dtrs Set CheckIn = '$CheckIn', BreakOut =
'$Breakout', BreakIn = '$Breakin', CheckOut = '$Checkout'");
}
//this is my conditions to identify whether the TIME/HOUR is
//Stated as CheckIn, Breakout, Breakin, or Checkout
if($NewState == "Check In" || $State == 'Check In' && $Exception == "OK") {
if($Exception == "Invalid" || $Exception == "Repeat")
{}
else {
$CheckIn = $hours;
}
}
if($State == 'Out' && $Exception == "Out") {
if($Exception == "Invalid" || $Exception == "Repeat")
{}
else {
$Breakout = $hours;
}
}
if($State == 'Out Back' && $Exception == "Out") {
if($Exception == "Invalid" || $Exception == "Repeat")
{}
else {
$Breakin = $hours;
}
}
if($NewState == "Check Out" || $State == "Check Out" && $Exception == "OK") {
if($NewState == "Check In")
{}
else {
$Checkout = $hours;
}
}
}
if($sql2)
{
if($sql2)
{
?>
<script type="text/javascript">
alert('File Upload Successful!');
</script>
<?php
}
}
}
}
?>