SQL时间超过了 [英] SQL Time exceeds

查看:119
本文介绍了SQL时间超过了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个系统,根据到达时间和当前时间输出等待时间; (当前时间 - 到达时间)。我将如何编写代码以便;

I currently have a system that outputs a waiting time, given their arrival time and current time; (current time - arrival time). How would I programme the code so that;

if the waiting_time exceeds 3 hours then alert "patient must be seen next!"

这是我到目前为止计算waiting_time的代码。

Here is the code I have so far to calculate 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);
?>


推荐答案

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

然后您的结果以最长的等待时间排序。

Then your results are ordered with the longest wait first.

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

这篇关于SQL时间超过了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆