php - 如何在两个时间范围内从数据库中检索数据?
问题描述
我想按日期范围和时间范围过滤我的数据。我完成了日期范围,但暂时没有得到解决方案。
我想检索两个时间范围之间的数据。我怎么能那样做?
这是我的日期范围代码:
1) 阿贾克斯
<script>
$(document).ready(function(){
$.datepicker.setDefaults({
dateFormat: 'yy-mm-dd'
});
$(function(){
$("#from_date").datepicker();
$("#to_date").datepicker();
});
$('#filter').click(function(){
var from_date = $('#from_date').val();
var to_date = $('#to_date').val();
if(from_date != '' && to_date != '')
{
$.ajax({
url:"filter.php",
method:"POST",
data:{from_date:from_date, to_date:to_date},
success:function(data)
{
$('#order_table').html(data);
}
});
}
else
{
alert("Please Select Date");
}
});
});
</script>
2)SQL查询:
if(isset($_POST["from_date"], $_POST["to_date"])) {
$connect = mysqli_connect("localhost", "root", "", "data");
$output = '';
$query = "
SELECT * FROM date_filter
WHERE date BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."'
";
$result = mysqli_query($connect, $query);
$output .= '
<table class="table table-bordered">
<tr>
<th width="5%">ID</th>
<th width="30%">Customer Name</th>
<th width="12%"> Date</th>
<th width="12%"> Time</th>
</tr>
';
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'. $row["id"] .'</td>
<td>'. $row["customer_name"] .'</td>
<td>'. $row["date"] .'</td>
<td>'. $row["time"] .'</td>
</tr>
';
}
}
else
{
$output .= '
<tr>
<td colspan="5">No data Found</td>
</tr>
';
}
$output .= '</table>';
echo $output; } ?>
帮助我进行时间过滤。从数据库中检索数据。
解决方案
推荐阅读
- firebase - 创建 FirebaseAuth 实例创建并使用电子邮件和密码登录时收到错误
- docker - 如何使用相同的图像运行两个组件,将两个不同的参数传递给 docker-compose
- amazon-web-services - 允许 3 个不同环境之间的网络连接
- python - 如果单词没有任何数字,则拆分字符串
- python - 如何在时间图中绘制数组元素,每 5 秒显示一个值
- javascript - 如何在javascript中读取发送到点阵打印机的USB数据?
- mongodb - 将两个 lambda 函数合二为一?
- c++ - 为 esp-now 发送数据创建一个库
- java - 如何从 micronaut 框架内的服务访问 ApplicationContext?
- python - TensorFlow 的 `sample_from_datasets` 在收到“DirectedInterleave 选择了一个用尽的输入”警告时是否仍从数据集中采样?