Count the number of posts today and yesterday. how can I write phpmysql statements? Count the number of posts today and yesterday. how can I write php mysql statements? Urgent !!!
Reply to discussion (solution)
We recommend that you paste the table structure for analysis.
It is best to publish the structure of your data table because you do not know the format of the time field in your data table Post.
The simplest table structure is as follows: how do I 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 by 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
Someone once taught me that the where clause in mysql should use as few functions as possible, because the index will 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
Someone once taught me that the where clause in mysql should use as few functions as possible, because the index will be invalid.
Well, the where clause function you are talking about is SQL. it seems you're wrong.
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
Someone once taught me that the where clause in mysql should use as few functions as possible, because the index will be invalid.
Well, the where clause function you are talking about is SQL. it seems you're wrong.
If you want to simplify the process, you 'd better 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
Someone once taught me that the where clause in mysql should use as few functions as possible, because the index will be invalid.
Well, the where clause function you are talking about is SQL. it seems you're wrong.
If you want to simplify the process, you 'd better 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
Someone once taught me that the where clause in mysql should use as few functions as possible, because the index will be invalid.
Well, the where clause function you are talking about is SQL. it seems you're wrong.
Sorry: SQL