我想通过使用PHP在表中显示一些带有日历日期的数据,如果表中没有日历日期,则可以正常工作,所以我真的不知道如何使用以下代码来完成它;
如果没有日历日期,结果就可以了。
EID: Full Name: Access Date: In: Out: Remarks:
006 Simon Kwok-AC 2019/01/03 Thu 14:15:41 18:40:02
006 Simon Kwok-AC 2019/01/04 Fri 08:49:17 18:32:51
006 Simon Kwok-AC 2019/01/07 Mon 08:42:45 18:48:05
006 Simon Kwok-AC 2019/01/08 Tue 08:53:50 18:04:55
006 Simon Kwok-AC 2019/01/09 Wed 09:01:27 18:07:18
006 Simon Kwok-AC 2019/01/10 Thu 08:50:21 18:03:21
006 Simon Kwok-AC 2019/01/11 Fri 08:49:55 18:13:57
006 Simon Kwok-AC 2019/01/14 Mon 08:51:02 18:47:16
006 Simon Kwok-AC 2019/01/15 Tue 09:04:24 18:07:44
006 Simon Kwok-AC 2019/01/16 Wed 08:41:20 18:46:08
Total No. of rows: 10
带有日历日期的意外结果
警告:odbc_fetch_array():第3行的C:\ xampp \ htdocs \ grandfrog \ rpt.php中的3不是有效的ODBC结果资源
警告:odbc_free_result():第3行中C:\ xampp \ htdocs \ grandfrog \ rpt.php中的3不是有效的ODBC结果资源
警告:odbc_close():2在第85行的C:\ xampp \ htdocs \ grandfrog \ rpt.php中不是有效的ODBC-Link资源
Calendar Date: EID: Full Name: Access Date: In: Out: Remarks:
2019/01/01 Tue
2019/01/02 Wed
2019/01/03 Thu
2019/01/04 Fri
2019/01/05 Sat
2019/01/06 Sun
2019/01/07 Mon
2019/01/08 Tue
2019/01/09 Wed
2019/01/10 Thu
2019/01/11 Fri
2019/01/12 Sat
2019/01/13 Sun
2019/01/14 Mon
2019/01/15 Tue
2019/01/16 Wed
Total No. of rows: 16
预期结果
Calendar Date: EID: Full Name: Access Date: In: Out: Remarks:
2019/01/01 Tue
2019/01/02 Wed
2019/01/03 Thu 006 Simon Kwok-AC 2019/01/03 Thu 14:15:41 18:40:02
2019/01/04 Fri 006 Simon Kwok-AC 2019/01/04 Fri 08:49:17 18:32:51
2019/01/05 Sat
2019/01/06 Sun
2019/01/07 Mon 006 Simon Kwok-AC 2019/01/07 Mon 08:42:45 18:48:05
2019/01/08 Tue 006 Simon Kwok-AC 2019/01/08 Tue 08:53:50 18:04:55
2019/01/09 Wed 006 Simon Kwok-AC 2019/01/09 Wed 09:01:27 18:07:18
2019/01/10 Thu 006 Simon Kwok-AC 2019/01/10 Thu 08:50:21 18:03:21
2019/01/11 Fri 006 Simon Kwok-AC 2019/01/11 Fri 08:49:55 18:13:57
2019/01/12 Sat
2019/01/13 Sun
2019/01/14 Mon 006 Simon Kwok-AC 2019/01/14 Mon 08:51:02 18:47:16
2019/01/15 Tue 006 Simon Kwok-AC 2019/01/15 Tue 09:04:24 18:07:44
2019/01/16 Wed 006 Simon Kwok-AC 2019/01/16 Wed 08:41:20 18:46:08
Total No. of rows: 16
编码
if ($_POST['period']!='' && $_POST['to']!=''){
$date1 = date('Y/m/d',strtotime($_POST['period']));
$date2 = date('Y/m/d',strtotime($_POST['to']));
$date3 = $date1;
$in = date('H:i:s',strtotime($_POST['in']));
$out = date('H:i:s',strtotime($_POST['out']));
$con=odbc_connect("attend","","gf123");
ini_set('max_execution_time', 300);
if($date1 < $date2){
if($con){
$sql="select accessrec.eid, employee.fullname, accessrec.accessdate, ".
"MIN(AccessRec.accesstime) AS firstime, ".
"MAX(AccessRec.accesstime) AS lastime ".
"from accessRec left join employee on accessrec.eid=employee.eid ".
"WHERE employee.fullname='".$_POST['staff']."' ".
"GROUP BY accessrec.eid, employee.fullname, accessrec.accessdate";
$result=odbc_exec($con,$sql);
$items = 0;
echo "<table id='dataTable' class='form' border='1'><tr> ".
"<th>Calendar Date:</th> ".
"<th>EID:</th> ".
"<th>Full Name:</th> ".
"<th>Access Date:</th> ".
"<th>In:</th> ".
"<th>Out:</th> ".
"<th>Remarks:</th></tr> ";
while ($date3<=$date2){
echo "<tr><td><input type='text' name='caldate". $date3 ."' value='". date('Y/m/d D', strtotime($date3)) ."' /></td>";
while ($row_whlist=odbc_fetch_array($result)){
if(date('Y/m/d',strtotime($row_whlist['accessdate'])) == $date3){
if((date('Y/m/d',strtotime($row_whlist['accessdate'])) >= $date1) && (date('Y/m/d',strtotime($row_whlist['accessdate'])) <= $date2)){
echo "<td><input type='text' name='eid[". $row_whlist['eid'] ."]' value='". $row_whlist['eid'] ."' /></td>";
echo "<td><input type='text' name='fullname[". $row_whlist['eid'] ."]' value='". $row_whlist['fullname'] ."' /></td>";
echo "<td><input type='text' name='accessdate[". $row_whlist['eid'] ."]' value='". date('Y/m/d D', strtotime($row_whlist['accessdate'])) ."' /></td>";
if(date('H:i:s',strtotime(str_pad($row_whlist['firstime'],6,0,STR_PAD_LEFT))) > $in){
echo "<td><input type='text' name='firstime[". $row_whlist['eid'] ."]' value='". date('H:i:s',strtotime(str_pad($row_whlist['firstime'],6,0,STR_PAD_LEFT))) ."' style='background-color:red;' /></td>";
}
else {
echo "<td><input type='text' name='firstime[". $row_whlist['eid'] ."]' value='". date('H:i:s',strtotime(str_pad($row_whlist['firstime'],6,0,STR_PAD_LEFT))) ."' /></td>";
}
if(date('H:i:s',strtotime(str_pad($row_whlist['lastime'],6,0,STR_PAD_LEFT))) < $out){
echo "<td><input type='text' name='lastime[". $row_whlist['eid'] ."]' value='". date('H:i:s',strtotime(str_pad($row_whlist['lastime'],6,0,STR_PAD_LEFT))) ."' style='background-color:red;' /></td>";
}
else {
echo "<td><input type='text' name='lastime[". $row_whlist['eid'] ."]' value='". date('H:i:s',strtotime(str_pad($row_whlist['lastime'],6,0,STR_PAD_LEFT))) ."' /></td>";
}
echo "<td><input type='text' maxlength='20' name='remarks[". $row_whlist['eid'] ."]' /></td></tr>";
}
}
else {
echo "<td></td";
echo "</tr>";
}
}
odbc_free_result($result);
odbc_close($con);
$items++;
$date3 = date('Y/m/d/', strtotime('+1 day', strtotime($date3)));
}
echo "</table>";
$error = "Total No. of rows: $items";
}
}
else {
$error="Incorrect date range";
}
}
else {
$error="The date range cannot be empty";
}