我为这个微不足道的问题道歉,花了很多时间谷歌搜索这个问题的答案。请帮忙.. 我有学生出勤时间表和学生出勤率表的时间表。我想要的是将学生的日程安排与他的出勤情况进行比较。
表格时间表
ID | stud_id | day | timein | timeout | schedule_hour |
1 | 8888 | Monday| 08:00AM | 09:00AM | 1 |
2 | 8888 | Monday| 10:00AM | 12:00PM | 2 |
3 | 8888 | Monday| 01:00PM | 03:00PM | 2 |
4 | 8888 |Tuesday| 07:00AM | 09:00AM | 2 |
5 | 8888 |Tuesday| 03:00PM | 04:00PM | 1 |
6 | 8888 |Tuesday| 06:00PM | 08:00PM | 2 |
表出席率
ID | stud_id | day | timein | timeout | hour |
1 | 8888 | Monday| 07:55AM | 09:10AM |1.15 |
2 | 8888 | Monday| 09:51AM | 12:03PM |2.12 |
3 | 8888 | Monday| 12:50PM | 03:05PM |2.15 |
4 | 8888 |Tuesday| 06:53AM | 09:15AM |2.22 |
5 | 8888 |Tuesday| 02:50PM | 04:06PM |1.16 |
6 | 8888 |Tuesday| 05:52PM | 08:09PM |2.17 |
7 | 8888 |Tuesday| 09:52PM | 10:09PM |1.17 |
php代码如下: -
<?php
$query=$conn->query("SELECT *
FROM student a,attendance d,schedule e
WHERE a.student_id = d.student_id
AND d.student_id = e.student_id
AND a.student_id = $get_id")or die(mysql_error());
$totalhour = 0;
$totalitems = 0;
function hourandmin($time1){
$hour = 0;
$minute = 0;
while($time1 > 1.0){
$hour = $hour + 1;
$time1 = $time1 - 1;
}
if($time1 < 1.0){
$minute = $time1 * 60;
}
$time1 = round($hour).".".round($minute)."";
return $time1;
}
while($row = $query->fetch()){
$date = strtotime($row['login']);
$date2 = strtotime($row['logout']);
$hour = ($date2 - $date) / (60*60);
if ($hour < 0){
$hour = 0;
}
?>
<tr>
<td><?php echo $row['student_id']; ?></td>
<td><?php echo $row['day']; ?></td>
<td><?php echo $row['timein']; ?></td>
<td><?php echo $row['timeout']; ?></td>
<td><?php echo hourandmin((($hour))); ?></td>
<td><?php echo $schedule_hour; ?></td>
</tr>
<?php } ?>
我不知道如何输出计划时间 所以例如他在第7排的考勤表上,但由于他没有时间安排,所以输出是超时的
ID | stud_id | day | timein | timeout | hour |schedule_hour
1 | 8888 | Monday| 07:55AM | 09:10AM | 1.15| 1
2 | 8888 | Monday| 09:51AM | 12:03PM | 2.12| 2
3 | 8888 | Monday| 12:50PM | 03:05PM | 2.15| 2
4 | 8888 |Tuesday| 06:53AM | 09:15AM | 2.22| 2
5 | 8888 |Tuesday| 02:50PM | 04:06PM | 1.16| 1
6 | 8888 |Tuesday| 05:52PM | 08:09PM | 2.17| 2
7 | 8888 |Tuesday| 09:52PM | 10:09PM | 1.17| overtime
答案 0 :(得分:0)
希望这有帮助
SELECT tatt.stud_id, tatt.day, tatt.timein, tatt.timeout, tatt.hour,tsched.schedule_hour FROM table_attendance tatt INNER JOIN table_schedule tsched ON tsched.stud_id = tatt.stud_id AND tsched.day = tatt.day AND tatt.timein <= tsched.timein AND tatt.timeout > tsched.timeout;
答案 1 :(得分:0)
<?php
$query=$conn->
query("
select a.student_id, d.timein, d.timeout, e.timein, e.timeout
from student a
inner join attendance d on a.student_id = d.student_id
inner join schedule e on a.student_id = e.student_id
where a.student_id = $get_id
")or die(mysql_error());
$totalhour = 0;
$totalitems = 0;
function hourandmin($time1){
$hour = 0;
$minute = 0;
while($time1 > 1.0){
$hour = $hour + 1;
$time1 = $time1 - 1;
}
if($time1 < 1.0){
$minute = $time1 * 60;
}
$time1 = round($hour).".".round($minute)."";
return $time1;
}
while($row = $query->fetch()){
$date = strtotime($row['d.login']);
$date2 = strtotime($row['d.logout']);
$hour = ($date2 - $date) / (60*60);
if ($hour < 0){
$hour = 0;
}
function schedule($date, $date2){
$date3 = strtotime($row['e.timein']);
$date4 = strtotime($row['e.timeout']);
if $date1 < $date3 && $date2 > $date4 {
$schedule_hour = $date4 - $date3;
else {
$schedule_hour = round($hour);
}
}
?>
<tr>
<td><?php echo $row['student_id']; ?></td>
<td><?php echo $row['day']; ?></td>
<td><?php echo $row['timein']; ?></td>
<td><?php echo $row['timeout']; ?></td>
<td><?php echo hourandmin((($hour))); ?></td>
<td><?php echo $schedule_hour; ?></td>