php后台关于根据某个相同的日期进行分组
php
这篇文章介绍的内容是关于php后台关于根据某个相同的日期进行分组 ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
接口中发现需要需要将每天(及时Unix时间不同),因为unix时间不同,需要将这个时间转成年月日这样,然后作为条件来查询这一天直播的历史数据。然后去这一天所有的数据,技术遇到的问题是,如何将这一天的数据放在一起,用sql分组不可以,因为uninx时间是不同的。所以我采用了函数循环比例进行分组。 **没进行分组的代码**
登录后复制
public function merchants_dynamic() { if ($params = Request::instance()->isPost()) { $p = empty($params["p"]) ? 1 :$params["p"]; $pageSize = empty($params["pagesize"]) ? 20 : $params["pagesize"]; $merchants_id = input('merchants_id');//商家商户id if (!$merchants_id) error("商户店铺id不能为空"); $list = Db::name('live_store')->alias("a") ->field("a.live_store_id,d.share,d.watch_nums,d.end_time,b.title,b.apply_id,b.cover_img,b.class_id,c.business_img,c.company_name") ->join("apply b",'a.room_id=b.room_id') ->join("merchants c","b.merchants_id=c.gl_merchants_id") ->join("live d","d.live_id=a.live_id") ->where(['c.gl_merchants_id'=>$merchants_id]) ->limit(($p-1)*$pageSize,$pageSize) ->select(); foreach ($list as $k=>$v){ $list[$k]['tag']=Db::name('live_class')->where(['live_class_id'=>$v['class_id']])->value('tag'); $list[$k]['end_time'] = date("Y-m-d",$v['end_time']); } if($list){ $data = $list; }else{ $data = []; } return success($data); } }
登录后复制
**这里没分组的结果** { "status": "ok", "data": [ { "live_store_id": "1", "share": "0", "watch_nums": "0", "end_time": "2018-04-12", "title": "测试开发", "apply_id": "35", "cover_img": "http://test.tstmobile.com/uploads//image/banner/20180412/37592d087ae79a103cea4417e77b6ddf.jpg", "class_id": "6", "business_img": "http://test.tstmobile.com/uploads/image/20171227/a7de424d12f4fdd77de7f6f9a35a8c48.jpg", "company_name": "金帅集团2", "tag": "直播售卖" }, { "live_store_id": "2", "share": "0", "watch_nums": "0", "end_time": "2018-04-13", "title": "测试开发", "apply_id": "35", "cover_img": "http://test.tstmobile.com/uploads//image/banner/20180412/37592d087ae79a103cea4417e77b6ddf.jpg", "class_id": "6", "business_img": "http://test.tstmobile.com/uploads/image/20171227/a7de424d12f4fdd77de7f6f9a35a8c48.jpg", "company_name": "金帅集团2", "tag": "直播售卖" }, { "live_store_id": "1", "share": "0", "watch_nums": "0", "end_time": "2018-04-12", "title": "测试开发", "apply_id": "35", "cover_img": "http://test.tstmobile.com/uploads//image/banner/20180412/37592d087ae79a103cea4417e77b6ddf.jpg", "class_id": "6", "business_img": "http://test.tstmobile.com/uploads/image/20171227/a7de424d12f4fdd77de7f6f9a35a8c48.jpg", "company_name": "王氏帝国2", "tag": "直播售卖" }, { "live_store_id": "2", "share": "0", "watch_nums": "0", "end_time": "2018-04-13", "title": "测试开发", "apply_id": "35", "cover_img": "http://test.tstmobile.com/uploads//image/banner/20180412/37592d087ae79a103cea4417e77b6ddf.jpg", "class_id": "6", "business_img": "http://test.tstmobile.com/uploads/image/20171227/a7de424d12f4fdd77de7f6f9a35a8c48.jpg", "company_name": "王氏帝国2", "tag": "直播售卖" } ] }
登录后复制
这里按照end_time进行分组,将同一天的数据分组出来代码段
public function merchants_dynamic() { if ($params = Request::instance()->isPost()) { $p = empty($params["p"]) ? 1 :$params["p"]; $pageSize = empty($params["pagesize"]) ? 20 : $params["pagesize"]; $merchants_id = input('merchants_id');//商家商户id if (!$merchants_id) error("商户店铺id不能为空"); $list = Db::name('live_store')->alias("a") ->field("a.live_store_id,d.share,d.watch_nums,d.end_time,b.title,b.apply_id,b.cover_img,b.class_id,c.business_img,c.company_name") ->join("apply b",'a.room_id=b.room_id') ->join("merchants c","b.merchants_id=c.gl_merchants_id") ->join("live d","d.live_id=a.live_id") ->where(['c.gl_merchants_id'=>$merchants_id]) ->limit(($p-1)*$pageSize,$pageSize) ->select(); foreach ($list as $k=>$v){ $list[$k]['tag']=Db::name('live_class')->where(['live_class_id'=>$v['class_id']])->value('tag'); $list[$k]['end_time'] = date("Y-m-d",$v['end_time']); } $res = array(); foreach ($list as $key=>$val){ $res[$val['end_time']][] = $val; } $re = []; foreach ($res as $ke=>$va){ $re[]['time'] = $ke; foreach ($re as $a=>$v){ $re[$a]['list'] = $va; } } if($list){ $data = $re; }else{ $data = []; } return success($data); } }
登录后复制
这里是结果
{ "status": "ok", "data": [ { "time": "2018-04-12", "list": [ { "live_store_id": "2", "share": "0", "watch_nums": "0", "end_time": "2018-04-13", "title": "测试开发", "apply_id": "35", "cover_img": "http://test.tstmobile.com/uploads//image/banner/20180412/37592d087ae79a103cea4417e77b6ddf.jpg", "class_id": "6", "business_img": "http://test.tstmobile.com/uploads/image/20171227/a7de424d12f4fdd77de7f6f9a35a8c48.jpg", "company_name": "金帅集团2", "tag": "直播售卖" }, { "live_store_id": "2", "share": "0", "watch_nums": "0", "end_time": "2018-04-13", "title": "测试开发", "apply_id": "35", "cover_img": "http://test.tstmobile.com/uploads//image/banner/20180412/37592d087ae79a103cea4417e77b6ddf.jpg", "class_id": "6", "business_img": "http://test.tstmobile.com/uploads/image/20171227/a7de424d12f4fdd77de7f6f9a35a8c48.jpg", "company_name": "王氏帝国2", "tag": "直播售卖" } ] }, { "time": "2018-04-13", "list": [ { "live_store_id": "2", "share": "0", "watch_nums": "0", "end_time": "2018-04-13", "title": "测试开发", "apply_id": "35", "cover_img": "http://test.tstmobile.com/uploads//image/banner/20180412/37592d087ae79a103cea4417e77b6ddf.jpg", "class_id": "6", "business_img": "http://test.tstmobile.com/uploads/image/20171227/a7de424d12f4fdd77de7f6f9a35a8c48.jpg", "company_name": "金帅集团2", "tag": "直播售卖" }, { "live_store_id": "2", "share": "0", "watch_nums": "0", "end_time": "2018-04-13", "title": "测试开发", "apply_id": "35", "cover_img": "http://test.tstmobile.com/uploads//image/banner/20180412/37592d087ae79a103cea4417e77b6ddf.jpg", "class_id": "6", "business_img": "http://test.tstmobile.com/uploads/image/20171227/a7de424d12f4fdd77de7f6f9a35a8c48.jpg", "company_name": "王氏帝国2", "tag": "直播售卖" } ] } ]}
登录后复制
END
相关推荐:
以上是php后台关于根据某个相同的日期进行分组的详细内容。更多信息请关注PHP中文网其他相关文章!
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前
By 尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
1 个月前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
4 周前
By 尊渡假赌尊渡假赌尊渡假赌
击败分裂小说需要多长时间?
3 周前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保护它?
3 周前
By DDD

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

PHP 8.4 带来了多项新功能、安全性改进和性能改进,同时弃用和删除了大量功能。 本指南介绍了如何在 Ubuntu、Debian 或其衍生版本上安装 PHP 8.4 或升级到 PHP 8.4

CakePHP 是 PHP 的开源框架。它的目的是使应用程序的开发、部署和维护变得更加容易。 CakePHP 基于类似 MVC 的架构,功能强大且易于掌握。模型、视图和控制器 gu

Visual Studio Code,也称为 VS Code,是一个免费的源代码编辑器 - 或集成开发环境 (IDE) - 可用于所有主要操作系统。 VS Code 拥有针对多种编程语言的大量扩展,可以轻松编写
