這篇文章介紹的內容是關於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中文網其他相關文章!

要保護應用免受與會話相關的XSS攻擊,需採取以下措施:1.設置HttpOnly和Secure標誌保護會話cookie。 2.對所有用戶輸入進行輸出編碼。 3.實施內容安全策略(CSP)限制腳本來源。通過這些策略,可以有效防護會話相關的XSS攻擊,確保用戶數據安全。

优化PHP会话性能的方法包括:1.延迟会话启动,2.使用数据库存储会话,3.压缩会话数据,4.管理会话生命周期,5.实现会话共享。这些策略能显著提升应用在高并发环境下的效率。

theSession.gc_maxlifetimesettinginphpdeterminesthelifespanofsessiondata,setInSeconds.1)它'sconfiguredinphp.iniorviaini_set().2)abalanceisesneededeededeedeedeededto toavoidperformance andunununununexpectedLogOgouts.3)

在PHP中,可以使用session_name()函數配置會話名稱。具體步驟如下:1.使用session_name()函數設置會話名稱,例如session_name("my_session")。 2.在設置會話名稱後,調用session_start()啟動會話。配置會話名稱可以避免多應用間的會話數據衝突,並增強安全性,但需注意會話名稱的唯一性、安全性、長度和設置時機。

會話ID應在登錄時、敏感操作前和每30分鐘定期重新生成。 1.登錄時重新生成會話ID可防會話固定攻擊。 2.敏感操作前重新生成提高安全性。 3.定期重新生成降低長期利用風險,但需權衡用戶體驗。

在PHP中設置會話cookie參數可以通過session_set_cookie_params()函數實現。 1)使用該函數設置參數,如過期時間、路徑、域名、安全標誌等;2)調用session_start()使參數生效;3)根據需求動態調整參數,如用戶登錄狀態;4)注意設置secure和httponly標誌以提升安全性。

在PHP中使用會話的主要目的是維護用戶在不同頁面之間的狀態。 1)會話通過session_start()函數啟動,創建唯一會話ID並存儲在用戶cookie中。 2)會話數據保存在服務器上,允許在不同請求間傳遞數據,如登錄狀態和購物車內容。

如何在子域名間共享會話?通過設置通用域名的會話cookie實現。 1.在服務器端設置會話cookie的域為.example.com。 2.選擇合適的會話存儲方式,如內存、數據庫或分佈式緩存。 3.通過cookie傳遞會話ID,服務器根據ID檢索和更新會話數據。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

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

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

記事本++7.3.1
好用且免費的程式碼編輯器

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

SublimeText3 Linux新版
SublimeText3 Linux最新版