【问题标题】:Jquery datepicker not fetching results via URL from MySql datebase?Jquery datepicker 没有通过 URL 从 MySql 数据库中获取结果?
【发布时间】:2016-04-03 04:25:54
【问题描述】:

我正在努力找出为什么这不起作用,我试图通过 URL 从 jquery datepicker 请求中获取我的日期库中称为时间的 DATETIME 列中的任何日期?下面我添加了发送到服务器的 URL 和时间列的图片。

JAVASCRIPT:

  <label for="from">From</label>
  <input type="text" name="from" id="from"/>
  <label for="to">To:</label>
  <input type="text" name="to" id="to"/>

   $( "#from" ).datepicker();
   $( "#to" ).datepicker();

$( "#from" ).datepicker( "option", {dateFormat: 'dd-mm-yyT00:00:00', showAnim: 'show' });
$( "#to" ).datepicker( "option", {dateFormat: 'dd-mm-yyT23:59:59',showAnim: 'show'});

$('#to').val(to);
$('#from').val(from);

PHP:

var from = getParameterByName('from'); 
var to = getParameterByName('to');

var from = parseDateTime($('#from').val()); 
var to = parseDateTime($('#to').val()); 

my.php?=from='+from+'&to='+to+'&rand='+Math.random()

$query = 'SELECT * FROM register WHERE time BETWEEN ( "#from" ) AND  ( "#to" )';
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
echo $row['time']."<br>";
}

【问题讨论】:

  • 试试这个:$( "#from" ).datepicker( "setDate", new Date(from));
  • 谢谢,但这样做我只能得到日期而不是时间。
  • 你不能有时间在datepicker。您一定在寻找 DateTimePicker
  • 即使我仅将其更改为迄今为止,我仍然没有得到任何结果?
  • 提供的代码不完整..PHP 代码不是必需的。尝试提供一个包含输入字段的小提琴和您设置日期的努力..

标签: javascript php jquery mysql datepicker


【解决方案1】:

使用setDate 方法设置日期选择器的日期

$(function() {
  $("#datepicker").datepicker();
  $("#datepicker").datepicker("setDate", new Date('10/12/2012'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<input type="text" id="datepicker">

Fiddle here

您可以使用jquery-ui-timepicker-addon添加时间。

试试这个Fiddle 和格式化日期和时间的这个:https://jsfiddle.net/rayon_1990/2wpp2qc1/2/

【讨论】:

  • 前面在cmets中提到,datepicker没有时间可以用datetimepicker代替。
  • 感谢上面的代码,但这确实是通过 URL 从时间列中获取的吗?而且我还需要获取时间才能显示结果?
  • 老兄,在这里阅读文档:api.jqueryui.com/datepicker 你不能在 datepicker 中有 time。为此使用xdsoft.net/jqplugins/datetimepicker
  • 我正在使用这个 ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/…" /> 认为这可能是错误的?
猜你喜欢
  • 2021-07-24
  • 1970-01-01
  • 2020-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多