一、效果图

二、原始数据

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 之实现按日期进行分组、分页的更多相关文章

  1. 在使用pandas 0.23.4对日期进行分组排序时报错

    date_df["rank_num"] = date_df.groupby("issuer_id").report_date.agg("rank&qu ...

  2. 《Entity Framework 6 Recipes》中文翻译系列 (17) -----第三章 查询之分页、过滤和使用DateTime中的日期部分分组

    翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 3-12 分页和过滤 问题 你想使用分页和过滤来创建查询. 解决方案 假设你有如图3 ...

  3. springboot+mongodb 按日期分组分页查询

    List<Integer> types = new ArrayList<>(); types.add("条件1"); types.add("条件2 ...

  4. 【MySQL】条件查询之排序聚合分组分页查询

    排序查询 语法:order by 子句 order by 排序字段1 排序方式1 , 排序字段2 排序方式2... 排序方式: ASC:升序,默认的. DESC:降序. 注意: 如果有多个排序条件,则 ...

  5. 18 12 06 sql 的 基本语句 查询 条件查询 逻辑运算符 模糊查询 范围查询 排序 聚合函数 分组 分页 连接查询 自关联 子查询

    -- 数据的准备 -- 创建一个数据库 create database python_test charset=utf8; -- 使用一个数据库 use python_test; -- 显示使用的当前 ...

  6. MongoTemplate 分组分页复合条件查询

    一.前言 最近项目使用MongoDB作为数据主要存取的地方 又是第一次接触MongoDB,也是踩了不少坑... 维护数据无非就是增删改查,而里面最复杂的就是查询了 所以来总结一下有关MongoDB的查 ...

  7. 小程序开发笔记(八)—Js数组按日期分组显示数据

    数据分组展示有两种方式,一种是后端直接传入分组格式的Json数据,另一种是我们在前端自己转换格式,这里我们在前端处理转换按日期分组的数据格式 1.例如后端返回数据格式为: [{createtime:' ...

  8. mongodb按照日期分组统计

    目录 1.使用时间格式化方法 2.进行时间补偿(默认当前时区是东八区,即8x3600x1000=28800000) mongodb的默认时间是格林尼治时间,如果是要按照日期进行分组需要注意!!!. 解 ...

  9. MySQL分布式数据库架构:分库、分表、排序、分页、分组、实现教程

    MySQL分库分表总结: 单库单表 : 单库单表是最常见的数据库设计,例如,有一张用户(user)表放在数据库db中,所有的用户都可以在db库中的user表中查到. 单库多表 : 随着用户数量的增加, ...

随机推荐

  1. reference website

    reference website cplusplus http://www.cplusplus.com/reference/ cppreference https://en.cppreference ...

  2. MiniUI学习笔记一【转】

    MiniUI Api文档:http://miniui.com/docs/api/index.html 1.取组件值 传递form data,load发送 请求加载数据 <script type= ...

  3. 在IOS中根据圆心坐标、半径和角度计算圆弧上的点坐标

    /** 日期:2015-10-15 版本: 1.0.0 -------------------------------------------------------------- 功能说明 ---- ...

  4. 你不知道的javascript(上卷)读后感(二)

    this词法 熟悉ES6语法的开发者,箭头函数在涉及this绑定时的行为和普通函数的行为完全不一致.跟普通this绑定规则不一样,它使用了当前的词法作用域覆盖了this本来的值. 误解 this理解成 ...

  5. 你不知道的javascript(上卷)读后感(一)

    三剑客 编译,顾名思义,就是源代码执行前会经历的过程,分三个步骤, 分词/词法分析,将我们写的代码字符串分解成多个词法单元 解析/语法分析,将词法单元集合生成抽象语法树(AST) 代码生成,抽象语法树 ...

  6. Linux下安装php报错:libxml2 not found. Please check your libxml2 installation

    ubuntu/debian: apt-get install libxml2-dev centos/redhat: yum install libxml2-devel

  7. 【leetcode】566. Reshape the Matrix

    原题 In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a ne ...

  8. 重构drf项目后的manage.py报错的问题

    Python3.6 用Django连接mysql一直报错django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer ...

  9. c#系统预定义类型

  10. [Selenium3+python3.6]自动化测试3-八种元素元素定位(Firebug和firepath)

    参考http://www.cnblogs.com/yoyoketang/p/6123890.html   #coding=utf-8 from selenium import webdriverdri ...