We often see some historical data on today or by year and month, and we need to use time query.
Query by time, where Ymd represents the year, month and day respectively. Of course, you can also use one of the time items for flexible use.
1. Query this month’s data:
-
- (date_format(time field,'%Y%m%d')=date_format(DATE_SUB(curdate(), INTERVAL 0 MONTH),'%Y%m%d''))
Copy Code
2, query the data of the previous month: (where 1 represents the previous month)
-
- (date_format(time field,'%Y%m%d')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%Y%m%d''))
Copy Code
Some commonly used PHP statements to operate mysql:
-
-
//Query statement
- $query = "SELECT * FROM table";
- $resul = mysql_query($query) or die('SQL statement is incorrect:'.mysql_error()) ;
- $user = mysql_fetch_array($resul);
-
- //Loop query statement
- $query=mysql_query("select * FROM table");
- while($table = mysql_fetch_array($query)){
-
- //Loop Displayed content...
- }
-
- //New statement
- $query = "INSERT INTO table(aaa,bbb) VALUES ('$aaa','$bbb')";@mysql_query($query) or die ('New error:'.mysql_error());
-
- //Update statement
- $query = "UPDATE table SET aaa='$aaa',bbb='$bbb' WHERE id='$id'";
- @mysql_query($query) or die('Modify error:'.mysql_error());
//Delete statement
- $query = "DELETE FROM table WHERE id='$deleteid'" ;
- $result = mysql_query($query) or die('SQL statement error:'.mysql_error());
-
Copy code
|