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";

其中显示以下数据:

PatientID   Forename  Surname  Gender   Illness       Priority   Waiting Time
 625         Max       Courts    M      non-urgent    moderate    4 hours

如示例所示;等候时间为4小时;time当 a为MORE THAN4 小时时,我需要一段代码来检测和提醒;回显警报。

我尝试过的示例代码;

if $waitingtime == >4 hours 
then echo "patient must be seen!"

编辑完整代码

<?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);
?>
4

1 回答 1

0

我正在使用 mysql_* 进行演示。您应该使用 mysqli_* 或 PDO。

$query = "SELECT PatientID, Forename, Surname, Gender, Illness, Priority, Arrival_time, TIME_FORMAT(ABS(TIMEDIFF(CURTIME(), Arrival_time)),'%H') as Waiting_Time FROM Patient";

$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
if ($row['Waiting_Time '] > 4)
{
    echo "patient must be seen!"
}
于 2013-03-26T17:34:31.587 回答