gpt4 book ai didi

javascript - PHP MySQL 表的日期范围过滤器

转载 作者:行者123 更新时间:2023-11-30 22:18:19 25 4
gpt4 key购买 nike

我是PHP新手,想请教一下。如何设置日期范围过滤器?我试过教程 - 但它们似乎对我不起作用。

我有这个,但它没有任何功能。我正在尝试在 CRUD 表中实现它。

<form role="form" action="index.php" method="get">
<div class="form-group">
<input placeholder="Filter From" class="col-sm-2" type="text" id="from" name="from">
<input placeholder="To" class="col-sm-2" type="text" id="to" name="to">
<input style="padding-bottom:0px" class="btn btn-default" type="submit" name="go" value="filter range">
</div>
</form>

对于日期选择器,我使用它。

<script>
$(function(){

$("#from").datepicker({
defaultDate:"+lw",
changeMonth: true,
numberOfMonths:3,
onClose:function(selectedDate){
$("#to").datepicker("option","minDate",selectDate);
}
});

$("#to").datepicker({
defaultDate: "+1w",
changeMonth:true,
numberOfMonths: 3,
onClose: function(selectedDate){
$("#from").datepicker("option", "maxDate", selectedDate);
}
});
});
</script>

PHP 表,我正在尝试在...上实现它

<?php  
$connect = mysqli_connect("localhost", "root", "root", "appointments");
$output = '';
$sql = "SELECT * FROM appointments ORDER BY id DESC";
$result = mysqli_query($connect, $sql);
$output .= '

<div class="table-responsive">

<table class="table table-bordered">
<tr>
<th>Select</th>
<th width="10%">Id</th>
<th width="40%">Name</th>
<th width="40%">Email</th>
<th width="40%">Address</th>
<th width="10%">phoneNumber</th>
<th width="10%">appointmentTime</th>
<th width="10%">appointmentDate</th>
<th width="50%">message</th>
<th width="10%">delete</th>

</tr>';
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
$output .= '

<tr id="'.$row["id"].'">

<td><input type="checkbox" name="id" value="'.$row["id"].'"></td>
<td>'.$row["id"].'</td>
<td class="name" data-id1="'.$row["id"].'" contenteditable>'.$row["name"].'</td>
<td class="email" data-id2="'.$row["id"].'" contenteditable>'.$row["email"].'</td>
<td class="address" data-id2="'.$row["id"].'" contenteditable>'.$row["address"].'</td>
<td class="phoneNumber" data-id2="'.$row["id"].'" contenteditable>'.$row["phoneNumber"].'</td>
<td class="appointmentTime" data-id2="'.$row["id"].'" contenteditable>'.$row["appointmentTime"].'</td>
<td class="appointmentDate" data-id2="'.$row["id"].'" contenteditable>'.$row["appointmentDate"].'</td>
<td class="message" data-id2="'.$row["id"].'" contenteditable>'.$row["message"].'</td>
<td><button type="button" name="delete_btn" data-id3="'.$row["id"].'" class="btn btn-xs btn-danger btn_delete">Delete This Row</button></td>
</tr>
';
}

}
else
{

$output .= '<tr><td colspan="10">Data not Found</td></tr>';
}


$output .= '</table>
<div align="center">
<button type="button" name="delete" id="delete">Delete</button>
</div>
</div> ';
echo $output;

?>

最佳答案

您应该获取日期范围的值,以便您可以根据输入的日期范围来调整约会日期。

试试这个!

PHP:

<?php

//get date range value
if (isset($_GET['go'])) {

$date_from = $_GET['from'];
$date_to = $_GET['to'];
}

SQL:

$sql = "SELECT * 
FROM appointments
WHERE appointmentDate
BETWEEN '$date_from' AND '$date_to'
ORDER BY id
DESC";

关于javascript - PHP MySQL 表的日期范围过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37476773/

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