我可以在phpmyadmin中执行请求,以显示今天日期和用户选择的日期之间的天数:
SELECT DATEDIFF(CURDATE(),date_instructed
)ASDAYS from date_tester
..但我认为这不会更新所有表格,只会在表格中创建新记录时更新。
因此,任何人都可以建议使用用户输入的日期动态更新/计算列中的天数的最佳方法。
它甚至应该放在专栏中吗?或者我应该使用PHP来回显网页上每一行的结果。
如果我应该用脚本操作'date_instructed',然后在html表格中单独输入它是一个链接,告诉我如何做到这一点?
非常感谢
<?php
include 'dbh.php';
?>
<table class="table table-sm table table-bordered
table table-hover table table-striped "> <!--, table table-inverse-->
<thead class="thead-inverse">
<tr class="warning">
<th>First Name</th>
<th>Last</th>
<th>Date Instructed</th>
<th>Days On Market</th>
</tr>
</thead>
<?php
$query = "SELECT first_name, last_name, date_instructed , days_onmarket
FROM date_tester";
$result = mysqli_query($conn, $query);
while ($date_tester = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>" . $date_tester['first_name'] . "</td>";
echo "<td>" . $date_tester['last_name'] . "</td>";
echo "<td>" . $date_tester['date_instructed'] . "</td>";
}
?>
</tbody>
</table>
</div>
答案 0 :(得分:0)
据我所知,这就是你所需要的:
$query = "SELECT first_name, last_name, date_instructed , days_onmarket, DATEDIFF(CURDATE(), 'date_instructed') AS DAYS FROM date_tester";
$result = mysqli_query($conn, $query);
while ($date_tester = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>" . $date_tester['first_name'] . "</td>";
echo "<td>" . $date_tester['last_name'] . "</td>";
echo "<td>" . $date_tester['date_instructed'] . "</td>";
echo "<td>" . $date_tester['DAYS'] . "</td>";
}