一、效果图

二、原始数据

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. webapi IHttpActionResult无引用和config.MapHttpAttributeRoutes()无引用解决办法

    1. 打开NuGet,打开方法 工具->库程序包管理器->程序包管理器控制台,如下图所示: 2. 输入如下命令Install-Package Microsoft.AspNet.WebApi ...

  2. 【原创】大叔经验分享(89)docker启动openjdk执行jmap报错

    docker启动openjdk后,可以查看进程 # docker exec -it XXX jps 10 XXX.jar 可见启动的java进程id一直为10,然后可以执行jvm命令,比如 # doc ...

  3. Django rest-framework框架-content-type

    表结构讨论: 是用一张表价格策略表来记录两种不同的价格策略 content-type原理: 使用一张表来记录不同课程的价目,增加一行表名称 注释: 适用于多张表关联一张表的情况 会自动生成这种的结构: ...

  4. Spring IOC原理分析

    IOC IOC(Inversion of Control)控制反转:所谓的控制反转,就是把原先需要我们代码自己实现对象的创建和依赖,反转给容器来实现.那么必然Spring需要创建一个容器,同时需要创建 ...

  5. wepy全局拦截器

    wepy有支持全局拦截器,但是请求需要使用wepy.request().then(): 在app.wpy文件中配置以下内容,与data同级 constructor(){ super(); this.u ...

  6. 图片预加载的插件使用-jquery.imgpreload.min.js

    使用方法: //图片预加载 var the_images = [];//新建一个数组,然后将要加载的图片地址推入这个数组中: the_images.push( 'bg.jpg' ); var load ...

  7. C++ STL 之 函数对象适配器

    谓词是指普通函数或重载的 operator()返回值是 bool 类型的函数对象(仿函数).如果operator 接受一个参数,那么叫做一元谓词,如果接受两个参数,那么叫做二元谓词,谓词可作为一个判断 ...

  8. 鼠标指针光标样式css cursor default pointer hand url

    一.cursor语法与结构 1.cursor语法:cursor : auto | crosshair | default | hand | move | help | wait | text | w- ...

  9. burpsuite暴力破解dvwa的登录密码

    前提准备条件: 1.下载安装dvwa,下载链接地址:http://www.dvwa.co.uk/. 2.安装php+mysql环境,我用的是这个软件(phpStudy)下载地址:https://www ...

  10. JS (二)

    ]1 函数 1 函数就是一段待执行的代码段 2 函数可以实现功能的封装,可以实现代码的复用 3 函数使用: 1 函数声明 2 函数调用 4 语法: 1 函数声明 1 使用function关键字进行函数 ...