gpt4 book ai didi

PHP/MYSQL使用datediff显示mysql记录年龄

转载 作者:行者123 更新时间:2023-11-29 11:10:52 25 4
gpt4 key购买 nike

我是 PHP/MYSQL 新手,我正在尝试使用 DATEIFF 显示数据库中所有记录的年龄,如代码第 17 行所示,但它只是赢了'不工作。我需要有人帮我解决这个问题。

$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>&nbsp;Batch</th>
<th><i class='icon_ol'></i>&nbsp;Date Received</th>
<th><i class='icon_clock_alt'></i>&nbsp;Age when Received</th>
<th><i class='icon_clock_alt'></i>&nbsp;Current Age</th>
<th><i class='icon_star'></i>&nbsp;NO of Birds</th>
<th><i class='icon_info'></i>&nbsp;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'] . "&nbsp;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);
?>

最佳答案

您可以在主选择中选择

  $result = mysqli_query($con,
"SELECT
growers.BATCH,
growers.`BIRTH DAY`,
growers.AGE,
DATEDIFF(NOW(),growers.`BIRTH DAY`) AS CURRENT_AGE,
growers.`NO OF BIRDS`
FROM growers; "
);


echo "<table class='table table-striped table-advance table-hover'>
<tbody>
<tr>
<th><i class='icon_profile'></i>&nbsp;Batch</th>
<th><i class='icon_ol'></i>&nbsp;Date Received</th>
<th><i class='icon_clock_alt'></i>&nbsp;Age when Received</th>
<th><i class='icon_clock_alt'></i>&nbsp;Current Age</th>
<th><i class='icon_star'></i>&nbsp;NO of Birds</th>
<th><i class='icon_info'></i>&nbsp;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'] . "&nbsp;Week(s)" . "</td>";
echo"<td>" . $row['CURRENT_AGE'] . "</td>";
echo"<td>" . $row['NO OF BIRDS'] . "</td>";
echo"<td>" . $row['AGE'] . "</td>";
echo"</tr>";
}
echo "</table>";

mysqli_close($con);
?>

关于PHP/MYSQL使用datediff显示mysql记录年龄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40579111/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com