我是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