日期范围的查询

WBOY
Release: 2016-06-23 13:59:38
Original
1003 people have browsed it

想默认打开网页后显示查询昨日的数据
又可在文本框中输入想要查询的日期后点查询
我写的代码如下

	$mindate=$_GET['mindate'];	$maxdate=$_GET['maxdate'];	$sql="SELECT * from `khxx` where $mindate and $maxdate";
Copy after login

	<form action="wel.php" method="get">		<input class="inp" type="text" name="mindate" value="<?php echo $mindate=date("Y-m-d",strtotime("-1 day"));?>" />至        <input class="inp" type="text" name="maxdate" value="<?php echo $maxdate=date("Y-m-d",strtotime("-1 day"));?>" />		<input class="sub" type="submit" value="统计"/>	</form>
Copy after login

这样写有两个问题
1、打开后没有直接根据文本框的内容查询结果
2、因为input 中定义了value内容 虽然写入别的日期点提交后结果查询出来了可文本框内的值又回复原样


回复讨论(解决方案)

显然你的sql语句是错的。

$mindate = isset($_GET['mindate'])?$_GET['mindate']:date("Y-m-d",strtotime("-1 day"));$maxdate = isset($_GET['maxdate'])?$_GET['maxdate']:date("Y-m-d",strtotime("-1 day"));	<form action="wel.php" method="get">		<input class="inp" type="text" name="mindate" value="<?php echo $mindate;?>" />至        <input class="inp" type="text" name="maxdate" value="<?php echo $maxdate;?>" />		<input class="sub" type="submit" value="统计"/>	</form>
Copy after login

$sql="SELECT * from `khxx` where $mindate and $maxdate"; 有问题.

如果你数据库的日期字段为 addtime,要这样写
$sql="SELECT * from `khxx` where addtime>'".$mindate."' and addtime

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template