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