php 根据输入 开始时间 结束时间 获取数据库中表中记录
我要做的是一个统计页面 查询条件是根据输入(js点击选择时间)开始时间 结束时间 点确定按钮查询这时间段记录
数据库字段:
id int(10)
ip varchar(50)
time varchar(50)
type varchar(50)
开始日期:<input type="text" name="time" onfocus="c.showMoreDay = false;c.show(this);" /> 结束日期:<input type="text" name="time" onfocus="c.showMoreDay = false;c.show(this);" /> <input type="submit" value="确定" />
下面是一个表格:
内容是类型和对应数量
请各位帮下忙,刚接触统计
[解决办法]
开始日期:<input type="text" name="timeStart" onfocus="c.showMoreDay = false;c.show(this);" /> 结束日期:<input type="text" name="timeEnd" onfocus="c.showMoreDay = false;c.show(this);" /> <input type="submit" value="确定" />
$t1=$_POST['timeStart'];
$t2=$_POST['timeEnd'];
$sql="select type,count(*) from tt where time BETWEEN '$t1' AND '$t2' group by type";
$result=mysql_query($sql);
while($row=mysql_fetch_row($result)){
echo $row[0].' '.$row[1].'<br>';
}
if(!empty($t1) && !empty($t2)){
$sql="select type,count(*) from tt where time BETWEEN '$t1' AND '$t2' group by type";
}else{
$sql="select type,count(*) from total_counter group by type";
}
$result=mysql_query($sql);
$t1 = $_POST['timeStart'];
$t2 = $_POST['timeEnd'];
$t = array(1);
if($t1) $r[] = "time>='$t1'";
if($t2) $r[] = "time<='$t2'";
$t = join(' and ', $t);
$sql = "select type,count(*) from total_counter where $t group by type";