Count the number of posts today and yesterday. how can I write phpmysql statements?

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.