Home > Backend Development > PHP Tutorial > PHP +MySQL 如何时间按天数分页?

PHP +MySQL 如何时间按天数分页?

WBOY
Release: 2016-06-06 20:20:32
Original
1415 people have browsed it

mysql 中有a表,有字段time,时间戳格式

如果数统计出记录跨度的天数,比如今天有n条记录产生,2015年12月1号,有m条记录产生,那么统计出来应该得到数是2,只为记录只 今天,和 2015年12月1号 这两天产生过记录。

比如今天有记录,昨天有记录,还有2015年12月1号 有记录,如何找出这‘前三天’的所有数据

.....后来自己想到一种...............................................

<code>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</code>
Copy after login
Copy after login

得到数组 ,PHP用 count(array) 可以算总天数

<code>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</code>
Copy after login
Copy after login

得到“前三天”统计情况, 取出数组 头 (20160111 ),尾(20160108 ) 转成时间戳,

<code>$start ,$end;

SELECT * FROM c_content where inputtime between $end and $start;</code>
Copy after login
Copy after login

回复内容:

mysql 中有a表,有字段time,时间戳格式

如果数统计出记录跨度的天数,比如今天有n条记录产生,2015年12月1号,有m条记录产生,那么统计出来应该得到数是2,只为记录只 今天,和 2015年12月1号 这两天产生过记录。

比如今天有记录,昨天有记录,还有2015年12月1号 有记录,如何找出这‘前三天’的所有数据

.....后来自己想到一种...............................................

<code>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</code>
Copy after login
Copy after login

得到数组 ,PHP用 count(array) 可以算总天数

<code>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</code>
Copy after login
Copy after login

得到“前三天”统计情况, 取出数组 头 (20160111 ),尾(20160108 ) 转成时间戳,

<code>$start ,$end;

SELECT * FROM c_content where inputtime between $end and $start;</code>
Copy after login
Copy after login

123456789

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template