我是PHP/MYSQL的新手,我試圖從我的數據庫中使用DATEIFF
顯示所有記錄的年齡,如我的代碼的第17行所示,但它只是將無法工作。我需要有人幫助我解決這個問題。PHP/MYSQL使用datediff顯示mysql記錄的年齡
$result = mysqli_query($con,"SELECT * FROM growers");
echo "<table class='table table-striped table-advance table-hover'>
<tbody>
<tr>
<th><i class='icon_profile'></i> Batch</th>
<th><i class='icon_ol'></i> Date Received</th>
<th><i class='icon_clock_alt'></i> Age when Received</th>
<th><i class='icon_clock_alt'></i> Current Age</th>
<th><i class='icon_star'></i> NO of Birds</th>
<th><i class='icon_info'></i> View More</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo"<tr>";
echo"<td>" . $row['BATCH'] . "</td>";
echo"<td>" . $row['BIRTH DAY'] . "</td>";
echo"<td>" . $row['AGE'] . " Week(s)" . "</td>";
echo"<td>" . "SELECT DATEDIFF("NOW()", "$row['BIRTH DAY']") AS CURRENT AGE". "</td>";
echo"<td>" . $row['NO OF BIRDS'] . "</td>";
echo"<td>" . $row['AGE'] . "</td>";
echo"</tr>";
}
echo "</table>";
mysqli_close($con);
?>
行'回聲 「」。 「SELECT DATEDIFF(」NOW()「,」$ row ['BIRTH DAY']「)as CURRENT AGE」。 「」'真的很混亂。您正試圖執行查詢並輸出結果,但實際上只顯示查詢。根據@ scaisEdge的回答建議,在第一行中計算查詢中的DATEDIFF()。 – karliwson