0

我正在尝试使用 Jquery UI datepicker 按日期范围过滤查询,但我总是收到 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))
    ?>
4

1 回答 1

2

$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'))");
于 2013-06-17T21:13:19.087 回答