PHP 之实现按日期进行分组、分页
一、效果图

二、原始数据
array(6) {
[0]=>
array(8) {
["id"]=>
string(1) "6"
["userid"]=>
string(1) "1"
["friend_id"]=>
string(3) "843"
["content"]=>
string(10) "你好啊
"
["date_entered"]=>
string(19) "2019-08-01 08:42:07"
["thumb"]=>
string(116) "http://wx.qlogo.cn/mmopen/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw/0"
["visittime"]=>
int(1564620127)
["date"]=>
string(5) "08:42"
}
[1]=>
array(8) {
["id"]=>
string(1) "5"
["userid"]=>
string(1) "1"
["friend_id"]=>
string(3) "843"
["content"]=>
string(6) "哈哈"
["date_entered"]=>
string(19) "2019-08-01 08:41:58"
["thumb"]=>
string(116) "http://wx.qlogo.cn/mmopen/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw/0"
["visittime"]=>
int(1564620118)
["date"]=>
string(5) "08:41"
}
[2]=>
array(8) {
["id"]=>
string(1) "4"
["userid"]=>
string(1) "1"
["friend_id"]=>
string(3) "843"
["content"]=>
string(11) "8月1好啦"
["date_entered"]=>
string(19) "2019-08-01 08:41:47"
["thumb"]=>
string(116) "http://wx.qlogo.cn/mmopen/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw/0"
["visittime"]=>
int(1564620107)
["date"]=>
string(5) "08:41"
}
[3]=>
array(8) {
["id"]=>
string(1) "3"
["userid"]=>
string(1) "1"
["friend_id"]=>
string(3) "843"
["content"]=>
string(3) "456"
["date_entered"]=>
string(19) "2019-07-31 15:51:17"
["thumb"]=>
string(116) "http://wx.qlogo.cn/mmopen/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw/0"
["visittime"]=>
int(1564559477)
["date"]=>
string(5) "15:51"
}
[4]=>
array(8) {
["id"]=>
string(1) "2"
["userid"]=>
string(1) "1"
["friend_id"]=>
string(3) "843"
["content"]=>
string(3) "123"
["date_entered"]=>
string(19) "2019-07-31 15:50:23"
["thumb"]=>
string(116) "http://wx.qlogo.cn/mmopen/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw/0"
["visittime"]=>
int(1564559423)
["date"]=>
string(5) "15:50"
}
[5]=>
array(8) {
["id"]=>
string(1) "1"
["userid"]=>
string(1) "1"
["friend_id"]=>
string(3) "843"
["content"]=>
string(9) "开始啦"
["date_entered"]=>
string(19) "2019-07-31 15:47:24"
["thumb"]=>
string(116) "http://wx.qlogo.cn/mmopen/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw/0"
["visittime"]=>
int(1564559244)
["date"]=>
string(5) "15:47"
}
}
三、PHP处理函数
function groupVisit($visit)
{
$curyear = date('Y');
$visit_list = [];
foreach ($visit as $v) {
if ($curyear == date('Y', $v['visittime'])) {
$date = date('m月d日', $v['visittime']);
} else {
$date = date('Y年m月d日', $v['visittime']);
}
$visit_list[$date][] = $v;
}
return $visit_list;
}
处理后数据:
array(2) {
["08月01日"]=>
array(3) {
[0]=>
array(8) {
["id"]=>
string(1) "6"
["userid"]=>
string(1) "1"
["friend_id"]=>
string(3) "843"
["content"]=>
string(10) "你好啊
"
["date_entered"]=>
string(19) "2019-08-01 08:42:07"
["thumb"]=>
string(116) "http://wx.qlogo.cn/mmopen/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw/0"
["visittime"]=>
int(1564620127)
["date"]=>
string(5) "08:42"
}
[1]=>
array(8) {
["id"]=>
string(1) "5"
["userid"]=>
string(1) "1"
["friend_id"]=>
string(3) "843"
["content"]=>
string(6) "哈哈"
["date_entered"]=>
string(19) "2019-08-01 08:41:58"
["thumb"]=>
string(116) "http://wx.qlogo.cn/mmopen/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw/0"
["visittime"]=>
int(1564620118)
["date"]=>
string(5) "08:41"
}
[2]=>
array(8) {
["id"]=>
string(1) "4"
["userid"]=>
string(1) "1"
["friend_id"]=>
string(3) "843"
["content"]=>
string(11) "8月1好啦"
["date_entered"]=>
string(19) "2019-08-01 08:41:47"
["thumb"]=>
string(116) "http://wx.qlogo.cn/mmopen/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw/0"
["visittime"]=>
int(1564620107)
["date"]=>
string(5) "08:41"
}
}
["07月31日"]=>
array(3) {
[0]=>
array(8) {
["id"]=>
string(1) "3"
["userid"]=>
string(1) "1"
["friend_id"]=>
string(3) "843"
["content"]=>
string(3) "456"
["date_entered"]=>
string(19) "2019-07-31 15:51:17"
["thumb"]=>
string(116) "http://wx.qlogo.cn/mmopen/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw/0"
["visittime"]=>
int(1564559477)
["date"]=>
string(5) "15:51"
}
[1]=>
array(8) {
["id"]=>
string(1) "2"
["userid"]=>
string(1) "1"
["friend_id"]=>
string(3) "843"
["content"]=>
string(3) "123"
["date_entered"]=>
string(19) "2019-07-31 15:50:23"
["thumb"]=>
string(116) "http://wx.qlogo.cn/mmopen/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw/0"
["visittime"]=>
int(1564559423)
["date"]=>
string(5) "15:50"
}
[2]=>
array(8) {
["id"]=>
string(1) "1"
["userid"]=>
string(1) "1"
["friend_id"]=>
string(3) "843"
["content"]=>
string(9) "开始啦"
["date_entered"]=>
string(19) "2019-07-31 15:47:24"
["thumb"]=>
string(116) "http://wx.qlogo.cn/mmopen/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw/0"
["visittime"]=>
int(1564559244)
["date"]=>
string(5) "15:47"
}
}
}
{"08\u670801\u65e5":[{"id":"6","userid":"1","friend_id":"843","content":"\u4f60\u597d\u554a\n","date_entered":"2019-08-01 08:42:07","thumb":"http:\/\/wx.qlogo.cn\/mmopen\/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw\/0","visittime":1564620127,"date":"08:42"},{"id":"5","userid":"1","friend_id":"843","content":"\u54c8\u54c8","date_entered":"2019-08-01 08:41:58","thumb":"http:\/\/wx.qlogo.cn\/mmopen\/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw\/0","visittime":1564620118,"date":"08:41"},{"id":"4","userid":"1","friend_id":"843","content":"8\u67081\u597d\u5566","date_entered":"2019-08-01 08:41:47","thumb":"http:\/\/wx.qlogo.cn\/mmopen\/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw\/0","visittime":1564620107,"date":"08:41"}],"07\u670831\u65e5":[{"id":"3","userid":"1","friend_id":"843","content":"456","date_entered":"2019-07-31 15:51:17","thumb":"http:\/\/wx.qlogo.cn\/mmopen\/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw\/0","visittime":1564559477,"date":"15:51"},{"id":"2","userid":"1","friend_id":"843","content":"123","date_entered":"2019-07-31 15:50:23","thumb":"http:\/\/wx.qlogo.cn\/mmopen\/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw\/0","visittime":1564559423,"date":"15:50"},{"id":"1","userid":"1","friend_id":"843","content":"\u5f00\u59cb\u5566","date_entered":"2019-07-31 15:47:24","thumb":"http:\/\/wx.qlogo.cn\/mmopen\/PiajxSqBRaEJKa1QdSvmwdHzRA6Kw4O72ItIxNJTbvwP6eUcIxIFjr6pmnMYOPzAZLxXB4xFfn63s1iaAYV8Zfbw\/0","visittime":1564559244,"date":"15:47"}]}
四、前端部分代码
var result = "";
for (var i = 0; i < date.length; i++) {
//判断是否在数组中存在,存在则追加列表,不存在则显示追加日期
if (contains(arr2, date[i]) == false) {
result += `<li class="aui-list-header" style="background: #fff;line-height: inherit;border-bottom: 1px solid #f5f5f5;padding: .5rem 0 .5rem .75rem;font-size: .7rem;">
` + date[i] + `
</li>`;
arr2.push(date[i]);
}
for (var j = 0; j < data[date[i]].length; j++) {
result += `<li class="aui-list-item">
<div class="aui-media-list-item-inner">
<div class="aui-list-item-media" style="width: 3rem;text-align: center;">
<img class="icon-item" src="` + data[date[i]][j].thumb + `" alt="">
</div>
<div class="aui-list-item-inner" style="align-items: center;">
<div class="aui-list-item-text" style="height: 100%;">
<div class="aui-list-item-title" style="font-size: .7rem !important;">新增记录:<span style="color: #f00;">` + data[date[i]][j].content + `</span></div>
<div class="aui-list-item-right user-come" style="font-size: .6rem !important;">` + data[date[i]][j].date + `</div>
</div>
</div>
</div>
</li>`;
}
}
PHP 之实现按日期进行分组、分页的更多相关文章
- 在使用pandas 0.23.4对日期进行分组排序时报错
date_df["rank_num"] = date_df.groupby("issuer_id").report_date.agg("rank&qu ...
- 《Entity Framework 6 Recipes》中文翻译系列 (17) -----第三章 查询之分页、过滤和使用DateTime中的日期部分分组
翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 3-12 分页和过滤 问题 你想使用分页和过滤来创建查询. 解决方案 假设你有如图3 ...
- springboot+mongodb 按日期分组分页查询
List<Integer> types = new ArrayList<>(); types.add("条件1"); types.add("条件2 ...
- 【MySQL】条件查询之排序聚合分组分页查询
排序查询 语法:order by 子句 order by 排序字段1 排序方式1 , 排序字段2 排序方式2... 排序方式: ASC:升序,默认的. DESC:降序. 注意: 如果有多个排序条件,则 ...
- 18 12 06 sql 的 基本语句 查询 条件查询 逻辑运算符 模糊查询 范围查询 排序 聚合函数 分组 分页 连接查询 自关联 子查询
-- 数据的准备 -- 创建一个数据库 create database python_test charset=utf8; -- 使用一个数据库 use python_test; -- 显示使用的当前 ...
- MongoTemplate 分组分页复合条件查询
一.前言 最近项目使用MongoDB作为数据主要存取的地方 又是第一次接触MongoDB,也是踩了不少坑... 维护数据无非就是增删改查,而里面最复杂的就是查询了 所以来总结一下有关MongoDB的查 ...
- 小程序开发笔记(八)—Js数组按日期分组显示数据
数据分组展示有两种方式,一种是后端直接传入分组格式的Json数据,另一种是我们在前端自己转换格式,这里我们在前端处理转换按日期分组的数据格式 1.例如后端返回数据格式为: [{createtime:' ...
- mongodb按照日期分组统计
目录 1.使用时间格式化方法 2.进行时间补偿(默认当前时区是东八区,即8x3600x1000=28800000) mongodb的默认时间是格林尼治时间,如果是要按照日期进行分组需要注意!!!. 解 ...
- MySQL分布式数据库架构:分库、分表、排序、分页、分组、实现教程
MySQL分库分表总结: 单库单表 : 单库单表是最常见的数据库设计,例如,有一张用户(user)表放在数据库db中,所有的用户都可以在db库中的user表中查到. 单库多表 : 随着用户数量的增加, ...
随机推荐
- bootstrap实现Carousel旋转木马(焦点图)
引入bootstrap相关文件后,在html中写如下代码: <div class="col-lg-9" > <!-- Carousel============== ...
- z-index和transform,你真的了解吗?
z-index和transform是CSS中的属性,但很少同学将二者联系到一起,感觉他们八杆子打不上.事实真的是这样吗?如果你也不能确认,这篇文章就值得你花点时间阅读.因为阅读完了,你会有所收获的. ...
- 【转载】salesforce 零基础开发入门学习(六)简单的数据增删改查页面的构建
salesforce 零基础开发入门学习(六)简单的数据增删改查页面的构建 VisualForce封装了很多的标签用来进行页面设计,本篇主要讲述简单的页面增删改查.使用的内容和设计到前台页面使用的 ...
- SMTP命令
SMTP(Simple Mail Transfer Protocol)简单邮件传输协议 Basic Commands: HELO(Hello):标识用户身份 MAIL FROM:发件人地址 RCPT ...
- linux内存管理初学
虚拟内存模型 Linux 内核本身并不运行在虚拟空间中,其使用的是物理寻址模式. 物理内存被分割为界面,一个内存页面的大小由PAGE_SIZE宏决定. 虚拟地址空间的方式使程序员可以将巨大的结构用于连 ...
- MySQL 查询大于“时间字段”15分钟、1小时、1天的数据
以下代码中times为时间字段,类型为datetime 1.查询大于times十五分钟的数据 //大于号后面都是获取times十五分钟后的时间select*from table where now() ...
- 不常见的sql错误处理方法(1)
select @@global.sql_mode, mysql5.7 导致 group查询出错 set @@global.sql_mode='' # mysql重启就失效了: phpstudy -&g ...
- Flutter——AppBar组件(顶部导航组件)
AppBar组件的常用属性如下: 属性 描述 leading 在标题前面显示的一个控件,在首页通常显示应用的 logo:在其他界面通常显示为返回按钮 title 标题,通常显示为当前界面的标题文字,可 ...
- Link monitoring
参考:https://www.ibm.com/support/knowledgecenter/en/linuxonibm/com.ibm.linux.z.l0wlcb00/l0wlcb00_miimo ...
- hibernate使用注解生成表,有时无法生成数据表的原因
待生成表中有字段“desc”或“descripe”等和hibernate关键字,导致和hibernate冲突