In PHP + MySQL, how does one paging by number of days?

Source: Internet
Author: User
Mysql has Table a with the field time. If the number of days in the record span is counted, for example, n records are generated today, and m records are generated in December 1, 2015, then, we can calculate that the number is 2, only for the record to be generated today, and for the past two days, January 1, December 1, 2015 .... Mysql has Table a with the time field in the timestamp format.

If the number of days in the record span is counted, for example, if n records are generated today and m records are generated in December 1, 2015, the number of records is 2, only for today, and December 1, 2015.

For example, if there are records today, yesterday, and December 1, 2015, how can we find all the data for the 'previous three days '?

..... Then I thought of a kind ................................... ............

mysql> SELECT FROM_UNIXTIME(inputtime,'%Y%m%d') day,COUNT(id) COUNT FROM c_content GROUP BY day order by day desc ;+----------+-------+| day      | COUNT || 20160111 |    28 || 20160109 |    41 || 20160108 |    44 || 20160107 |    52 || 20160106 |    42 || 20160105 |    49 || 20151229 |    39 || 20151228 |    35 |+----------+-------+24 rows in set

Get the array. PHP usescount(array)Total number of days

mysql> SELECT FROM_UNIXTIME(inputtime,'%Y%m%d') day,COUNT(id) COUNT FROM c_content GROUP BY day order by day desc limit 0,3;+----------+-------+| day      | COUNT || 20160111 |    28 || 20160109 |    41 || 20160108 |    44 |+----------+-------+3 rows in set

Obtain the statistics of the previous three days. Get the array header (20160111) and the end (20160108) into a timestamp,

$start ,$end;SELECT * FROM c_content where inputtime between $end and $start;

Reply content:

Mysql has Table a with the time field in the timestamp format.

If the number of days in the record span is counted, for example, if n records are generated today and m records are generated in December 1, 2015, the number of records is 2, only for today, and December 1, 2015.

For example, if there are records today, yesterday, and December 1, 2015, how can we find all the data for the 'previous three days '?

..... Then I thought of a kind ................................... ............

mysql> SELECT FROM_UNIXTIME(inputtime,'%Y%m%d') day,COUNT(id) COUNT FROM c_content GROUP BY day order by day desc ;+----------+-------+| day      | COUNT || 20160111 |    28 || 20160109 |    41 || 20160108 |    44 || 20160107 |    52 || 20160106 |    42 || 20160105 |    49 || 20151229 |    39 || 20151228 |    35 |+----------+-------+24 rows in set

Get the array. PHP usescount(array)Total number of days

mysql> SELECT FROM_UNIXTIME(inputtime,'%Y%m%d') day,COUNT(id) COUNT FROM c_content GROUP BY day order by day desc limit 0,3;+----------+-------+| day      | COUNT || 20160111 |    28 || 20160109 |    41 || 20160108 |    44 |+----------+-------+3 rows in set

Obtain the statistics of the previous three days. Get the array header (20160111) and the end (20160108) into a timestamp,

$start ,$end;SELECT * FROM c_content where inputtime between $end and $start;

123456789

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.