我想通過這個簡單的計算顯示病人的等待時間;使用PHP顯示等待時間
waiting time (the clock time - the arrival time)
在插入表單中;我已經使用以下代碼將current_time(arrival_time)插入已成功的PATIENT表中。
// validate arrival time
date_default_timezone_set('Europe/London');
$time = time();
$sql="INSERT INTO Patient(Forename, Surname, Gender, Date_Of_Birth, Address, Patient_History, Illness, Priority, Arrival_Time)
VALUES('$patient_name', '$patient_lastname', '$gender', '$date', '$address', '$history', '$illness', '$priority', '$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, TIMEDIFF(Arrival_time,NOW()) 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);
?>
如何使用以下計算計算等待時間; (時鐘時間 - 到達時間)
**請注意:Arrival_Time類型爲TIME。
您的查詢中沒有'TIMEDIFF(Arrival_time,NOW())as Waiting_Time'是否一樣? – cipher 2013-03-25 16:27:37