PHP background about grouping on an identical date

Source: Internet
Author: User

This article introduces the content of the PHP background on the basis of a certain date group, has a certain reference value, now share to everyone, the need for friends can refer to

The interface is found to need to be daily (in time Unix time is different), because the Unix time is different, need to turn this time into months and months to this, and then as a condition to query this day's live history data. And then go to this day all the data, the technical problem is, how to put this day's data together, with SQL grouping can not, because the Uninx time is different. So I used the function loop scale to group.    * * Code that is not grouped * *
Public Function merchants_dynamic () {if ($params = Request::instance ()->ispost ()) {$p = Empty ($params ["P"])?                1: $params ["P"]; $pageSize = Empty ($params ["pageSize"])?                : $params ["pagesize"];                        $merchants _id = input (' merchants_id ');//Merchant Merchant ID if (! $merchants _id) Error ("Merchant Store ID cannot be empty"); $list = Db::name (' Live_store ')->alias ("a")->field ("a.live_store_id,d.share,d.watch_nums,d.end_t Ime,b.title,b.apply_id,b.cover_img,b.class_id,c.business_img,c.company_name ")->join (" Apply B ", ' a.ro om_id=b.room_id ')->join ("Merchants C", "b.merchants_id=c.gl_merchants_id")->j                    Oin ("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); }    }
* * There are no grouped results **{"status": "OK", "data": [{"live_store_id": "1", "Share" : "0", "watch_nums": "0", "end_time": "2018-04-12", "title": "Test Open "," apply_id ":" "," cover_img ":" http://test.tstmobile.com/uploads//image/banner/ 20180412/37592d087ae79a103cea4417e77b6ddf.jpg "," class_id ":" 6 "," business_img ":" Http://tes                    T.tstmobile.com/uploads/image/20171227/a7de424d12f4fdd77de7f6f9a35a8c48.jpg "," Company_Name ":" Golden Handsome Group 2 ", "Tag": "Live Sale"}, {"live_store_id": "2", "Share": " 0 "," watch_nums ":" 0 "," end_time ":" 2018-04-13 "," title ":" Test Open "," apply_id ":" "," cover_img ":" Http://test.tstmobile.com/uploads//image/banne R/20180412/37592d087ae79A103cea4417e77b6ddf.jpg "," class_id ":" 6 "," business_img ":" Http://test.tstmobile.com/uploa                       Ds/image/20171227/a7de424d12f4fdd77de7f6f9a35a8c48.jpg "," Company_Name ":" Golden Handsome Group 2 ",                     "Tag": "Live Sale"}, {"live_store_id": "1", "Share": "0",                     "Watch_nums": "0", "end_time": "2018-04-12", "title": "Test Development", "apply_id": "A", "cover_img": "http://test.tstmobile.com/uploads//image/banner/20180412/3759 2d087ae79a103cea4417e77b6ddf.jpg "," class_id ":" 6 "," business_img ":" http://test.t                     Stmobile.com/uploads/image/20171227/a7de424d12f4fdd77de7f6f9a35a8c48.jpg "," Company_Name ":" King's Empire 2 ", "Tag": "Live Sale"}, {"live_store_id": "2", "Share": "0 "," WAtch_nums ":" 0 "," end_time ":" 2018-04-13 "," title ":" Test Development "," APPL y_id ":" "", "cover_img": "Http://test.tstmobile.com/uploads//image/banner/20180412/37592d087ae79a103ce A4417e77b6ddf.jpg "," class_id ":" 6 "," business_img ":" Http://test.tstmobile.com/uplo Ads/image/20171227/a7de424d12f4fdd77de7f6f9a35a8c48.jpg "," Company_Name ":" King's Empire 2 "," Tag ": Live Sale"}]}


This is grouped by end_time, grouping data from the same day into code snippets

Public Function merchants_dynamic () {if ($params = Request::instance ()->ispost ()) {$p = Empty ($params ["P"])?                    1: $params ["P"]; $pageSize = Empty ($params ["pageSize"])?                    : $params ["pagesize"];                        $merchants _id = input (' merchants_id ');//Merchant Merchant ID if (! $merchants _id) Error ("Merchant Store ID cannot be empty"); $list = Db::name (' Live_store ')->alias ("a")->field ("a.live_store_id,d.share,d.watch_nums,d.end_t Ime,b.title,b.apply_id,b.cover_img,b.class_id,c.business_img,c.company_name ")->join (" Apply B ", ' a.ro om_id=b.room_id ')->join ("Merchants C", "b.merchants_id=c.gl_merchants_id")->j                    Oin ("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); }    }

here is the result

{"Status": "OK", "data": [{"Time": "2018-04-12", "list": [{                    "live_store_id": "2", "Share": "0", "watch_nums": "0", "End_time": "2018-04-13", "title": "Test Development", "apply_id": "A", "Co                    Ver_img ":" Http://test.tstmobile.com/uploads//image/banner/20180412/37592d087ae79a103cea4417e77b6ddf.jpg ", "class_id": "6", "business_img": "Http://test.tstmobile.com/uploads/image/20171227/a7de424d12f4fdd7                7de7f6f9a35a8c48.jpg "," Company_Name ":" Golden Handsome Group 2 "," tag ":" Live Sale "}, {"live_store_id": "2", "Share": "0", "watch_nums": "0                    "," End_time ":" 2018-04-13 "," title ":" Test Development "," 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/a7de424d12f4fdd77de            7f6f9a35a8c48.jpg "," Company_Name ":" King's Empire 2 "," tag ":" Live Sale "} ]}, {"Time": "2018-04-13", "list": [{"Live_st ore_id ":" 2 "," Share ":" 0 "," watch_nums ":" 0 "," end_time ":" 2018- 04-13 "," title ":" Test Development "," apply_id ":" A "," cover_img ":" http://t Est.tstmobile.com/uploads//image/banner/20180412/37592d087ae79a103cea4417e77b6ddf.jpg "," class_id ":" 6 " , "business_img": "http://test.tstmobile.com/uploads/image/20171227/a7de424d12f4fdd77de7f6f9a35a8c48.jp G ","Company_Name ":" Golden Handsome Group 2 "," tag ":" Live Sale "}, {" Live_store _id ":" 2 "," Share ":" 0 "," watch_nums ":" 0 "," end_time ":" 2018-04- "," "title": "Test Development", "apply_id": "A", "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": "King's Empire 2", "tag": "Live Sale"}]}

END

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.