我正在为医院编写剧本。在按周显示数据时,我遇到了问题。
我正在这样存储我的数据
nurse | ward | shift | sdate | week
1 | 2 | 1st | 2019-08-08 | 32
1 | 3 | 2nd | 2019-08-09 | 32
1 | 3 | 1st | 2019-08-10 | 32
1 | 1 | 2nd | 2019-08-12 | 33
1 | 2 | 3rd | 2019-08-13 | 33
1 | 4 | 2nd | 2019-08-15 | 33
1 | 2 | 1st | 2019-08-19 | 34
我想将其显示为
Week 32
Ward Shift Date
2 1st 2019-08-08
3 2nd 2019-08-09
3 1st 2019-08-10
Week 33
Ward Shift Date
2 2nd 2019-08-12
2 3rd 2019-08-13
4 2nd 2019-08-15
Week 34
Ward Shift Date
2 1st 2019-08-19
我尝试使用Group By Week(sdate)
,但它显示的内容却不是我想要的
答案 0 :(得分:2)
What you can do is to order by your data on the basis of date.
然后在脚本中,您可以尝试以这种格式修改数组:
$arrData =
[
[0] =>[
'nurse' => 1,
'ward' => 2,
'shift' => '1st',
'sdate' => '2019-08-08',
'week' => 32
],
[1] =>[
'nurse' => 1,
'ward' => 2,
'shift' => '1st',
'sdate' => '2019-08-08',
'week' => 33
]
]
排序方式将确保您保持一致的星期,即第32周之后将是第33周,而不是第32周。
脚本中可能要做的是:
$intPrevShift = -1;
foreach($arrData as $arrDatum){
if($arrDatum == $intPrevShift){
// Keep doing stuff
}
else{
echo 'Week: '. $arrDatum['week']
}
$intPrevShift = $arrDatum['week'];
}
希望你明白我的意思。
答案 1 :(得分:-1)
您是否尝试过从护士GROUP BY星期,日期中选择将星期,病房,班次,日期等作为“日期”,?
您正在尝试什么,结果将如何?