如何使用当前周数和未来十五周组装表(HTML + PHP)(29 + 15 = 44 and 37 + 15 = 52)
从可能具有水平或垂直结果的查询中获取数据的地方:
另一个困难是年度交换,如第9行所示
Year: 2015
Week: 42 + 15 = 57 (Max Week 52) >> 57-52 = 5
然后我们将进入
2015 42 ... 43 ... 44 ... 45 ... 46 ... 47 ... 48 ... 49 ... 50 ... 51 ... 52 ....
并在
2016 1 ... 2 .... 3 .... 4 .... 5 ...
示例:
答案 0 :(得分:0)
我解决了自己的疑问,感谢大家的关注。
代码用于解决我的疑问。
$date = new DateTime('first monday this week');
$weeks = 15;
$query_week = array();
while($weeks > 0) {
$endDate = clone $date;
$endDate->modify('+6 day');
$query_week[] = sprintf("(SELECT COUNT(*) FROM table1 WHERE table1.fieldA BETWEEN '%s' AND '%s' AND table1.fieldB = table2.fieldA) as week_%s", $date->format('Y-m-d'), $endDate->format('Y-m-d'), $date->format('W'));
$date->modify('+7 day');
$weeks--;
}
$query = sprintf('
SELECT table2.fieldA,
table2.fieldB,
table2.fieldC,
%s
FROM table2', implode(', ' . PHP_EOL, $query_week));
echo '<pre>';
echo $query;