Count the number of posts today, yesterday, how to write the PHP mysql statement? Urgent!!!
Reply to discussion (solution)
It is recommended to post the table structure for analysis
The structure of your data sheet is best sent because you don't know what format the time field of your data sheet post is.
The simplest table structure is as follows: If you ask, how do you write PHP mysql statements?
Select COUNT (ID) from table where Datetime=curdate ()-1 yesterday
Select COUNT (ID) from table where Datetime=curdate () today
Select Date_format (tb_send_date, '%y-%m-%d ') as Date, COUNT (*) as CNT from Tbl_name Group by To_days (tb_send_date) Order B Y desc limit 2
$today _rows= "SELECT COUNT (*) from table where tb_send_date>= '". Date (' y-m-d 00:00:00 '). "' and tb_send_date<= '". Date (' y-m-d 23:59:59 '). "'"; /Today $tomorrow=date ("y-m-d", Strtotime ("-1 day")); $tomorrow _rows= "SELECT COUNT (*) from table where tb_send_date>= '". $tomorrow. " 00:00:00 ' and tb_send_date<= ' ". $tomorrow." 23:59:59 ' ";; /Yesterday
I was taught that the WHERE clause in MySQL minimizes the use of functions because it causes the index to be invalid
$today _rows= "SELECT COUNT (*) from table where tb_send_date>= '". Date (' y-m-d 00:00:00 '). "' and tb_send_date<= '". Date (' y-m-d 23:59:59 '). "'"; /Today $tomorrow=date ("y-m-d", Strtotime ("-1 day")); $tomorrow _rows= "SELECT COUNT (*) from table where tb_send_date>= '". $tomorrow. " 00:00:00 ' and tb_send_date<= ' ". $tomorrow." 23:59:59 ' ";; /Yesterday
I was taught that the WHERE clause in MySQL minimizes the use of functions because it causes the index to be invalid
Well, the function of the where sentence you're talking about is SQL, and you seem to be mistaken.
Today
Select COUNT (*) from table where Date_format (Tb_send_date, "%y-%m-%d") =curdate ()
Yesterday
Select COUNT (*) from table where Date_format (Tb_send_date, "%y-%m-%d") =date_sub (Curdate (), INTERVAL 1 day)
$today _rows= "SELECT COUNT (*) from table where tb_send_date>= '". Date (' y-m-d 00:00:00 '). "' and tb_send_date<= '". Date (' y-m-d 23:59:59 '). "'"; /Today $tomorrow=date ("y-m-d", Strtotime ("-1 day")); $tomorrow _rows= "SELECT COUNT (*) from table where tb_send_date>= '". $tomorrow. " 00:00:00 ' and tb_send_date<= ' ". $tomorrow." 23:59:59 ' ";; /Yesterday
I was taught that the WHERE clause in MySQL minimizes the use of functions because it causes the index to be invalid
Well, the function of the where sentence you're talking about is SQL, and you seem to be mistaken.
If you want to simplify, it's better to change your database to a timestamp.
$today _rows= "SELECT COUNT (*) from table where tb_send_date>= '". Date (' y-m-d 00:00:00 '). "' and tb_send_date<= '". Date (' y-m-d 23:59:59 '). "'"; /Today $tomorrow=date ("y-m-d", Strtotime ("-1 day")); $tomorrow _rows= "SELECT COUNT (*) from table where tb_send_date>= '". $tomorrow. " 00:00:00 ' and tb_send_date<= ' ". $tomorrow." 23:59:59 ' ";; /Yesterday
I was taught that the WHERE clause in MySQL minimizes the use of functions because it causes the index to be invalid
Well, the function of the where sentence you're talking about is SQL, and you seem to be mistaken.
If you want to simplify, it's better to change your database to a timestamp.
$today _rows= "SELECT COUNT (*) from table where tb_send_date>= '". Date (' y-m-d 00:00:00 '). "' and tb_send_date<= '". Date (' y-m-d 23:59:59 '). "'"; /Today $tomorrow=date ("y-m-d", Strtotime ("-1 day")); $tomorrow _rows= "SELECT COUNT (*) from table where tb_send_date>= '". $tomorrow. " 00:00:00 ' and tb_send_date<= ' ". $tomorrow." 23:59:59 ' ";; /Yesterday
I was taught that the WHERE clause in MySQL minimizes the use of functions because it causes the index to be invalid
Well, the function of the where sentence you're talking about is SQL, and you seem to be mistaken.
Sorry, is the SQL