duankuangxie9070 2016-04-20 06:43
浏览 36
已采纳

如何在表中显示日期明智的mysql数据

I want to show machine maintenance table in my project ,currently i'm displaying all the data in single table, but now i want to display table in date wise .

SELECT * ,DATE_FORMAT(date,'%Y-%m-%d') as groupdate,SUM(operationtime) as usetime  FROM `logusages` WHERE machineid = '$id' GROUP BY groupdate,empCode"

Output of Query =

Array
(
    [workingLogs] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 13
                    [key] => 5BTIB4EoklT6dVfTUR4ezwb8T3xdeTAi
                    [machineid] => HIT232300
                    [empCode] => 1003
                    [employeeid] => Jon Doe
                    [date] => 2016-03-21 09:27:33
                    [time] => 11:22:00
                    [operationtime] => 1800
                    [groupdate] => 2016-03-21
                    [usetime] => 1800
                )

            [1] => stdClass Object
                (
                    [id] => 14
                    [key] => 5BTIB4EoklT6dVfTUR4ezwb8T3xdeTAi
                    [machineid] => HIT232300
                    [empCode] => 1003
                    [employeeid] => Jon Doe
                    [date] => 2016-03-22 09:27:33
                    [time] => 11:22:00
                    [operationtime] => 1800
                    [groupdate] => 2016-03-22
                    [usetime] => 1800
                )

            [2] => stdClass Object
                (
                    [id] => 8
                    [key] => 5BTIB4EoklT6dVfTUR4ezwb8T3xdeTAi
                    [machineid] => HIT232300
                    [empCode] => 1004
                    [employeeid] => Jon Doe
                    [date] => 2016-03-22 09:27:33
                    [time] => 11:22:00
                    [operationtime] => 1800
                    [groupdate] => 2016-03-22
                    [usetime] => 1800
                )

            [3] => stdClass Object
                (
                    [id] => 15
                    [key] => 5BTIB4EoklT6dVfTUR4ezwb8T3xdeTAi
                    [machineid] => HIT232300
                    [empCode] => 1003
                    [employeeid] => Jon Doe
                    [date] => 2016-03-23 09:27:33
                    [time] => 11:22:00
                    [operationtime] => 1800
                    [groupdate] => 2016-03-23
                    [usetime] => 3600
                )

            [4] => stdClass Object
                (
                    [id] => 9
                    [key] => 5BTIB4EoklT6dVfTUR4ezwb8T3xdeTAi
                    [machineid] => HIT232300
                    [empCode] => 1004
                    [employeeid] => Jon Doe
                    [date] => 2016-03-23 09:27:33
                    [time] => 11:22:00
                    [operationtime] => 1800
                    [groupdate] => 2016-03-23
                    [usetime] => 3600
                )

            [5] => stdClass Object
                (
                    [id] => 12
                    [key] => 5BTIB4EoklT6dVfTUR4ezwb8T3xdeTAi
                    [machineid] => HIT232300
                    [empCode] => 1003
                    [employeeid] => Jon Doe
                    [date] => 2016-03-25 09:27:33
                    [time] => 11:22:00
                    [operationtime] => 1800
                    [groupdate] => 2016-03-25
                    [usetime] => 1800
                )

            [6] => stdClass Object
                (
                    [id] => 11
                    [key] => 5BTIB4EoklT6dVfTUR4ezwb8T3xdeTAi
                    [machineid] => HIT232300
                    [empCode] => 1004
                    [employeeid] => Jon Doe
                    [date] => 2016-03-25 09:27:33
                    [time] => 11:22:00
                    [operationtime] => 1800
                    [groupdate] => 2016-03-25
                    [usetime] => 1800
                )

        )

)

I'm trying to handle using this code using in_array but that code not working

  foreach ($workingLogs as $key => $date) {
          if(in_array($date['groupdate']) = $date['groupdate']){
            $datewise[$date['groupdate']]=$date;
          }else{
            $datewise[]=$date;
          }

Currently my table look like ..

I want look like.

Please help

  • 写回答

4条回答 默认 最新

  • dou47278 2016-04-20 07:20
    关注

    You have a mistake in your code... You have to check the if statement with "==". Also, the in_array only returns a boolean. You can't compare it with a non boolean value

     foreach ($workingLogs as $key => $date) {
       if(array_key_exists('groupdate', $date) ){
         $datewise[$date['groupdate']]=$date;
       }else{
         $datewise[]=$date;
       }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像