gpt4 book ai didi

php - 按日期选择器范围对表进行排序

转载 作者:行者123 更新时间:2023-11-29 17:04:20 24 4
gpt4 key购买 nike

我尝试通过日期选择器范围(服务器端)对数据表进行排序,但无法使日期排序部分正常工作。肯定存在代码丢失和其他问题。

我错过了什么?

<html lang="en">
<head>
<title>List</title>
<script src="jquery-3.3.1.min.js"></script>
</head>
<body>
<h1 align="center">List</h1>
</br>
</br>
</br>
<center> <p class="search_input">
<form method="post" action="#">
<input type="date" name="dateFrom">&nbsp;&nbsp;&nbsp;<input type="date" name="dateTo">&nbsp;&nbsp;&nbsp;
<input type="submit" name="range" id="range" class="btn-info" />
</form>
</center>

<table align="center" cellspacing="0" cellpadding="0">
<thead class="fixedthead">
<th width="120px" style="text-align: center; color: navy">Name</th>
<th width="120px" style="text-align: center; color: navy">Description</th>
<th width="120px" style="text-align: center; color: navy">Date</th>
<th width="120px" style="text-align: center; color: navy">Open</th>
</thead>

<?php
//retrieve content via data picker range
$dateFrom = $_POST['dateFrom'];
$dateTo = $_POST['dateTo'];


$conn = mysqli_connect("localhost", "root", "", "order");
// get results from database
$result = mysqli_query($conn, "SELECT * FROM order.item WHERE date BETWEEN '$dateFrom' AND '$dateTo' ", MYSQLI_USE_RESULT)
or die(mysqli_error($conn));
while($row = mysqli_fetch_array( $result )) {
?>

<tbody>
<tr>
<td width="120px" style="text-align: center"><?php echo $row['name']; ?></td>
<td width="120px" style="text-align: center"><?php echo $row['description']; ?></td>
<td width="120px" style="text-align: center"><?php echo $row['date']; ?></td>
<td width="120px"><a href = "download.php?id=<?php echo $row['id']; ?>" style='text-decoration:none;'><button>View</button></a></td>
</tr>
</tbody>
</table><br><br><br>
<?php
}
?>

</body>
</html>

感谢任何帮助。谢谢大家!

最佳答案

对您的数据库一无所知...

$last_five_days = time() - 432000;
$sql = "SELECT * FROM order.item WHERE order.date > ".$last_five_days." ORDER BY order.date ASC";

如果此答案没有帮助,那么您需要向我们提供有关“日期选择器范围”含义的更多信息。

ORDER BY {column} ASC|DESC 按指定的列对行进行排序。默认为 ASC

我正在使用 WHERE 子句来设置您最近五天的要求。我假设 order.date (无论您实际命名它是什么)正在存储一个简单的 UNIX 时间戳。

关于php - 按日期选择器范围对表进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52124260/

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