我有一些似乎接近工作的代码。它似乎每天都能找到数据和组,但是星期几的标签不正确。
我有本周一,周二,周四和周五的数据。 输出标记为星期日,星期一,星期二,星期三。
所以我认为可能存在两个问题,标签并没有考虑没有任何数据的天数,因为输出在几天内没有中断。
* Gets the first weekday of that month and year
*
* @param int The day of the week (0 = sunday, 1 = monday ... , 6 = saturday)
* @param int The month (if false use the current month)
* @param int The year (if false use the current year)
*
* @return int The timestamp of the first day of that month
*
**/
function get_first_day($day_number=1, $month=false, $year=false)
{
$month = ($month === false) ? strftime("%m"): $month;
$year = ($year === false) ? strftime("%Y"): $year;
$first_day = 1 + ((7+$day_number - strftime("%w", mktime(0,0,0,$month, 1, $year)))%7);
return mktime(0,0,0,$month, $first_day, $year);
}
// Bar Plot Guest by weekday/month
$data_wk = array();
$label_wk = array();
$statistic = querySQL('statistic_weekday');
foreach ($statistic as $key => $value) {
foreach($value as $paxsum){
$label_wk[] = $key;
$data_wk[] = $paxsum;
}
}
<?php
foreach ($label_wk as $value) {
echo "<th>".strftime("%A", get_first_day($value, $_SESSION['statistic_month'], $_SESSION['selectedDate_year']))."</th>";
}
?>
我确实找到了这两个相似的帖子和代码,但没有解决我的问题。我尝试了第二个帖子改变$ first_day =值的解决方案,但仍然不正确。我可以让我在不同的一天开始,但由于它忽略了空白的日子,只有一些标签是正确的。
First saturday for a selected month and year
.mktime and .strftime help returning wrong day of week
如果有帮助,我的:查询:
case 'statistic_weekday':
$result = query("SELECT SUM(reservation_pax) AS paxsum FROM `$dbTables->reservations`
WHERE `reservation_wait`= '0' AND `reservation_hidden`= '0'
AND `reservation_outlet_id`='%d'
AND MONTH(reservation_date) = '%s'
AND YEAR(reservation_date) = '%s'
GROUP BY WEEKDAY(reservation_date)",
$_SESSION['outletID'], $_SESSION['statistic_month'], $_SESSION['selectedDate_year']);
return getRowList($result);