出勤表和卡会员表加入card member.id = attendance.card_member_id
在考勤表中,attendance_datetime
列记录了到达和离开时间
typeid = 1 :arrive,
typeid = 2 :leave
我想输出同一类的所有出勤记录的Excel 现在我可以输出记录,但出勤时间不正确, 例如在excel中,对于1220160007,正确的到达时间是15:01:07,离开的时间是17:01:07
EXCEL OUTPUT
Date Arrival Time Leaving Time
2017-11-23 15:01:07 17:15:07 1220160007
2017-11-23 15:45:41 17:01:07 1220160008
2017-11-23 15:25:41 16:59:40 1220160009
PHP代码
if (isset($_GET['classid'])) {
$class_id = $_GET['classid'];
echo $class_id;
}
//fromdate
if (isset($_GET['datesearch'])) {
$datesearch = $_GET['datesearch'];
}
//todate
if (isset($_GET['datesearch2'])) {
$datesearch2 = $_GET['datesearch2'];
}
//from date convert date format
$from= date("Y-n-j", strtotime($_GET['datesearch']) )."<br>";
//to date convert date format
$to = date("Y-n-j", strtotime($_GET['datesearch2']) );
//display table data from row 6
$rows = 6;
$sql2 = "SELECT card_member.id,
card_member.class_id,card_member.eng_name,attendance.card_member_id,
attendance.card_member_id,attendance.attendance_datetime,
attendance.type_id,attendance.on_time
FROM card_member
LEFT JOIN attendance ON card_member.id = attendance.card_member_id
WHERE str_to_date(attendance_datetime, '%Y-%m-%d')
BETWEEN str_to_date('$from','%Y-%m-%d' ) AND str_to_date('$to','%Y-%m-%d')
AND
card_member.class_id = '".$class_id."'";
$result = mysql_query($sql2) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$type_id = $row['type_id'];
$nametest = $row['eng_name'];
$attendance_datetime = $row['attendance_datetime'];
$on_time = $row['on_time'];
$date = date('Y-m-d', strtotime($attendance_datetime));
$cardId =$row['id'];
$cardmemberid =$row['card_member_id'];
$time = date('H:i:s', strtotime($attendance_datetime));
if ($on_time == '1') {
$status = "On time";
} else if ($on_time == '0' && $type_id == 3) {
$status = "Late & Early Leave";
} else if ($on_time == '0') {
$status = "Late";
} else if ($type_id == 3) {
$status = "Early Leave";
}
if ($type_id != 1 && $cardmemberid == $cardmemberid ) {
$rows--;
$sheet->setCellValue('D'.$rows, "{$time}");
}
else {
$sheet->setCellValue('A'.$rows, "{$nametest}")
->setCellValue('B'.$rows, "{$date}")
->setCellValue('C'.$rows, "{$time}")
->setCellValue('E'.$rows, "{$status}")
->setCellValue('F'.$rows, "{$cardmemberid}");
$sheet->getStyle('B'.$rows)->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$sheet->getStyle('C'.$rows)->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$sheet->getStyle('D'.$rows)->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$cardmemberid= $cardmemberid;
}
$rows++;
}
我想知道如何让特定学生的离开时间与他/她的到达时间相匹配,并在excel的同一行显示。 非常感谢