0
我已經做了一個函數,查詢一個MSSQL數據庫來獲取每日總數由代表列表。我將它們分成幾周,然後用ISO週數表示日期。在一週結束時,我共產生這樣的:如何在此foreach中顯示每日總數?
您可以從每星期會自動分離,則每行有一天,代表和它的總數據的圖像看到。在我放置紅線的地方,我希望能夠增加一行,但不能完全弄清楚如何去做,我猜測還有一個嵌套的foreach
?
下面是當前功能產生上述:
function getWorkInByDay()
{
global $db;
$data = '';
// Build query
$q = mssql_query("SELECT DATEPART(isowk,Datedb) AS 'Week', DAY(Datedb) AS 'Day', Ref1 AS 'Rep', SUM(PriceEst) AS 'Total', Datedb AS 'Date' FROM MainJobDetails WHERE MONTH(Datedb) = " . date('m') . " AND YEAR(Datedb) = " . date('Y') . " GROUP BY DATEPART(isowk,Datedb), DAY(Datedb), Ref1, Datedb",$db);
$weeks = array();
while($r = mssql_fetch_assoc($q)) {
$weeks[$r['Week']][] = $r;
}
foreach ($weeks as $w => $rs) {
$t = 0;
$data .= "<table class='data full-width'>";
$data .= "<thead><tr><td colspan='3'>". date('F'). " - Week ".$w."</td></tr></thead>";
foreach ($rs as $r) {
$data .= "<tr>";
$data .= "<td>".date('l',strtotime($r['Date']))."</td>";
$data .= "<td>".$r['Rep']."</td>";
$data .= "<td>£".number_format($r['Total'], 2, '.', ',')."</td>";
$data .= "</tr>";
$t += $r['Total'];
}
$data .= "<tr><td></td><td></td><td><strong>Total: £".number_format($t, 2, '.', ',')."</strong></td></tr>";
$data .= "</table>";
}
return $data;
}
任何幫助表示讚賞。
以獲得每個組彙總行,你可以使用簡單的旋轉功能,顯示一週柱以及 – sumit