Count the number of posts today, yesterday, how to write the PHP mysql statement?

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