0

I am having trouble with this. So, I created a from that allows you select a date range. Then from there, the form populates with records from the database based on the date range. Pretty easy.

However, the date field didn't work in firefox, so I tried switching it to jquery. and how it doesn't work. I am assuming it's something with the format. So here is my jquery code:

  <script>

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

and here is the mysql statement:

$sql = "SELECT * FROM v88374 WHERE date >= DATE_FORMAT('" . $from . "', '%Y/%m/%d') AND date <=  DATE_FORMAT('" . $to . "', '%Y/%m/%d')";

Any help is greatly appreciated. I need it to work in all browsers ahd the reason I switched jquery was because the basic date field wouldn't work in firefox....so if someone has a better fix for this then I am definitely open to it.

4

1 回答 1

0

您不应该在 SQL 查询中将日期视为字符串。在您的数据库中使用适当的数据类型(可能DATE)。然后,您应该参数化您的查询,而不是将值附加到字符串中。

格式问题应委托给您的 PHP 代码。将输入解析为一个datetime类,并将其作为参数传递。(使用该strptime函数进行解析。)

于 2013-07-24T16:00:27.097 回答