1

私は次のコードを考案しました。患者の待機時間と予想時間を計算します。患者が長時間待機している場合も、コードは警告をエコーする必要があります。

注意:Waiting_timeは、データベースではDATETIMEです。

これがコードです。

<?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,NOW() as now,ABS(TIMEDIFF(NOW(), Arrival_time)) 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()){

//Select the  expected and discharge time for this patient.
  $query2 = "SELECT Abs(TIMEDIFF(Expected_Time,'00:00:00')) as Expected,Abs(TIMEDIFF(Discharge_Time,'00:00:00')) as Discharge ".
                "FROM priority_time ".
                "WHERE Illness = '".$row->Illness."'".
                    " AND Priority = '".$row->Priority."'".
                ";";

    $result2 = mysqli_query($conn, $query2) or die("Invalid statement: ".$query2);

    $row2 = $result2->fetch_object();
    $expected =  $row2->Expected;

    $discharge  = $row2->Discharge;
    echo "expected-> ".$expected." discharge-> ".$discharge;

    if($expected > $discharge){
        echo "There is a problem with the database consistency, expectedTime must be less than dischargeTime!";
    }
    //Set the patient color.
    if($row->Waiting_Time <  $expected && $row->Waiting_Time <  $discharge){
        echo "<tr>";
    }
    if($row->Waiting_Time >=  $expected && $row->Waiting_Time <  $discharge){
        echo '<tr bgcolor="#FFFF00">';
    }
    if($row->Waiting_Time >  $expected && $row->Waiting_Time >  $discharge){
        echo '<tr bgcolor="#FF0000">';
    }

    //Print patient info
     echo 
      "<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 . "(".$expected."-".$discharge.") </td>";

    //Close row
    echo "</tr>";

}

echo "</table>";
mysqli_close($conn);
?>

編集:各行の[待機時間]列には、待機時間を秒単位で示し、括弧内にcurrentTimeマイナスと到着時間を示しています。これは確認のためです。待機時間をhh:mm:ssの形式に変換して、ユーザーがより適切に表現できるようにするにはどうすればよいですか?

表示中;

Waiting time 
01:15:42(10500.000000-10500.000000)

(10500.000000-10500.000000)が表示されるのはなぜですか?

4

2 に答える 2

0

これを試して:

gmdate("H:i:s", $seconds)

それでもうまくいかない場合は、秒を時間形式に変換する方法をご覧ください。

アップデート:

SQLステートメントでこれを行うには、次のようにしてみてください。

SELECT TIME_TO_SEC(TIMEDIFF('2013-03-27 12:00:00', '2013-03-27 10:00:00')) diff;

だからこのようなもの:

SELECT PatientID
, Forename
, Surname
, Gender
, Illness
, Priority
, Arrival_time
, NOW() as now
, TIME_TO_SEC(TIMEDIFF(NOW(), Arrival_time)) as Waiting_Time 
FROM Patient;

次に、この行を変更します。

<td>" . $row->Waiting_Time . "(".$expected."-".$discharge.") </td>

これに:

<td>" . gmdate("H:i:s", $row->Waiting_Time) . "(".$expected."-".$discharge.") </td>
于 2013-03-27T12:23:22.957 に答える
0

phpで日付と時刻を処理する場合、strtotime()はあなたの最大の友達です。幸運なことに、これに必要なのはdate()関数だけです。秒を読み取り可能な形式に変換するものは次のようになります。

$time = strtotime('now');
echo $time . '<br />';
$var =  date('H:i:s',$time);
echo $var;
于 2013-03-27T12:29:36.420 に答える