Php obtains records in the table in the database based on the input start time and end time. what I want to do is a statistics page & nbsp; the query condition is based on the input (js click to select a time) start time & nbsp; end time & nbsp; Click OK to query the database fields recorded during this period: id & nbsp; int (10) ip & nbsp; varchar (50) tim php obtains records from tables in the database based on the input start time and end time
What I want to do is to query the records of this time period according to the input (js click to select a time) start time end time point OK button
Database field:
Id int (10)
Ip varchar (50)
Time varchar (50)
Type varchar (50)
Start date: End date:
The following is a table:
Content is type and quantity
Please help me. I just got in touch with statistics
------ Solution --------------------
Start date: End date:
$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].'
';
}
------ Solution --------------------
Time varchar (50)
At least the input data must be corrected to conform to the time field format for comparison.
He didn't say that. I don't know.
------ Solution --------------------
The key is the database statement. The principle and practice are the same as the ID-based query. The second floor of the SQL statement is provided.
In addition, the landlord can download a time selection plug-in. after all, it is not ideal for users to manually enter the time. Describes a jq jquery-calendar. There are many style sheets on the net, and you can select your own style.
------ Solution --------------------
Time varchar (50)
The time you save is a string, so
10:43:20
2012-12-14 10: 43: 31 p
All are valid dates
If the input form is 10:43:22
At least two of them cannot be matched.
Reference:
Xuzuning: Do you not quite understand the format before the insertion time?
Xiebuqing
Another problem is that when you do not query time period records, the page displays all types of records in the database by default.
------ Solution --------------------
What is the date format you passed in.
------ Solution --------------------
Even if
'2014/1/14' and '2014-12-14 'are not equal
------ Solution --------------------
As long as the format can be unified, #1 code can be used.
------ Solution --------------------
Just judge it.
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);
------ Solution --------------------
This is better to adapt to various situations.
$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";