我目前有一个系统,根据到达时间和当前时间输出等待时间; (当前时间 - 到达时间)。我将如何编写代码以便;
if the waiting_time exceeds 3 hours then alert "patient must be seen next!"
这是我到目前为止计算waiting_time的代码。
<?php
$conn = mysqli_connect("localhost","root","") or die ("No connection");
mysqli_select_db($conn, "a&e") or die('Could not select database.');
$query = "SELECT PatientID, Forename, Surname, Gender, Illness, Priority, Arrival_time, TIME_FORMAT(ABS(TIMEDIFF(CURTIME(), Arrival_time)),'%H hours') as Waiting_Time FROM Patient";
$result = mysqli_query($conn, $query) or die("Invalid query");
echo "<table border='1'>
<tr>
<th>PatientID</th>
<th>Forename</th>
<th>Surname</th>
<th>Gender</th>
<th>Illness</th>
<th>Priority</th>
<th>Waiting Time</th>
</tr>";
while ($row = $result->fetch_object()){
echo "<tr>
<td>" . $row->PatientID . "</td>
<td>" . $row->Forename . "</td>
<td>" . $row->Surname . "</td>
<td>" . $row->Gender . "</td>
<td>" . $row->Illness . "</td>
<td>" . $row->Priority . "</td>
<td>" . $row->Waiting_Time . "</td>
</tr>";
}
echo "</table>";
mysqli_close($conn);
?>
答案 0 :(得分:0)
$query = "SELECT PatientID, Forename, Surname, Gender, Illness, Priority, Arrival_time,
TIME_FORMAT(ABS(TIMEDIFF(CURTIME(), Arrival_time)),'%H hours') as Waiting_Time
FROM Patient
ORDER BY TIMEDIFF(CURTIME(), Arrival_time) DESC";
然后您的结果会以最长的等待时间排序。
<?php
while ($row = $result->fetch_object()): ?>
<tr>
<td><?=$row->PatientID?></td>
<td><?=$row->Forename?></td>
<td><?=$row->Surname?></td>
<td><?=$row->Gender?></td>
<td><?=$row->Illness?></td>
<td><?=$row->Priority?></td>
<td><?=$row->Waiting_Time?>
<? if ($row->Waiting_Time >= 3): ?>
<strong>Patient must be seen!</strong>
<? endif; ?>
</td>
</tr>
<? endwhile; ?>