【发布时间】:2017-06-02 06:17:18
【问题描述】:
在此代码中,我将日期格式 dd-mm-yy 转换为 yy-mm-dd。当我回显$from 日期时,它会给出正确的日期(2017-6-1)。与echo $to 类似。
但是当我回显查询时,它无法获得$from 的值,但$to 它正确地获得了日期。 $from有什么问题?
这是我的代码...
<script language='javascript'>
jQuery(function($)
{
$("#from").datepicker({ dateFormat: 'dd-mm-yy' });
$("#to").datepicker({ dateFormat: 'dd-mm-yy' });
});
</script>
<input name="from" id="from" type="text" />
<input name="to" id="to" type="text" />
<?php
$froms = $_POST['from'];
list($day, $month, $year) = explode("-", $froms);
$from = "$year-$month-$day";
$too = $_POST['to'];
list($day, $month, $year) = explode("-", $too);
$to = "$year-$month-$day";
if($from = "$year-$month-$day" && $to = "$year-$month-$day")
{
echo "select * from students where (enquiry_date between '$from' and '$to')";
}
?>
结果:
select * from students where (enquiry_date between '1' and '2017-06-09') order by student_id
【问题讨论】:
-
if($from = "$year-$month-$day" && $to = "$year-$month-$day")很确定你想使用==而不是=另外你应该再考虑一下你的 IF 语句。 IMO 它没有任何意义,即使是双== -
我正在尝试这个@Twinfriends,但查询没有回显。
-
它不会显示,因为您的 if 语句没有任何意义。我不认为它是“真的”——所以它只是跳过了那部分。