gpt4 book ai didi

php - 使用 Jquery UI datepicker 过滤 MySQL 查询

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

我尝试使用 Jquery UI 日期选择器按日期范围过滤查询,但总是收到 SQL 错误。我还希望有一个日期范围的提交按钮,如果有人也可以帮助我的话。

代码是;

    <script type="text/javascript" language="javascript">
jQuery(function() {
jQuery( "#from" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate", selectedDate );
}
});
jQuery( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
onClose: function( selectedDate ) {
jQuery( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
});
</script>
<form action="" method="post">
<label style="margin: 0 10px 0 20px;" for="from">From</label>
<input style="padding: 3px; border-radius: 4px; opacity: none; background: #EEEEEE;" type="text" id="from" name="from" />
<label style="margin-left: 10px;" for="to">To</label>
<input style="padding: 3px; border-radius: 4px; background: #EEEEEE;" type="text" id="to" name="to" />
</form>

<?php
$from = $_POST['from'] ;
$to = $_POST['to'] ;

SELECT display_name as Author,
FROM posts p
WHERE p.post_status = 'publish' AND ((post_date >= $from) AND (post_date < $to))
?>

最佳答案

您需要在 $to$from 两边加引号

mysql_query("SELECT display_name as Author,
FROM posts p
WHERE p.post_status = 'publish' AND ((post_date >= '$from') AND (post_date < '$to'))");

关于php - 使用 Jquery UI datepicker 过滤 MySQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17156586/

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