我想在我的項目中顯示機器維護表,目前我在單個表中顯示所有數據,但現在我想以明智的方式顯示錶。查詢的如何在日期表中顯示mysql數據
SELECT * ,DATE_FORMAT(date,'%Y-%m-%d') as groupdate,SUM(operationtime) as usetime FROM `logusages` WHERE machineid = '$id' GROUP BY groupdate,empCode"
輸出=
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
)
)
)
我想使用此代碼使用in_array來處理,但該代碼不工作
foreach ($workingLogs as $key => $date) {
if(in_array($date['groupdate']) = $date['groupdate']){
$datewise[$date['groupdate']]=$date;
}else{
$datewise[]=$date;
}
目前我的桌子的樣子..
我想看起來像。
請幫
這似乎只是你需要做一個小的調整你的循環 – Strawberry