我正在使用以下方法来计算我的月度总数,它工作得很好,但我试图将每个月的名称放在每个总数的顶部,但我现在得到的只是月份:没有别的。
// Work Complete Monthly Totals
$query = $db->query("SELECT
MONTHNAME(dateofcompletion),
SUM(pricequoted) AS pricequotedtotal,
SUM(partprice) AS partpricetotal,
SUM(profit) AS profittotal,
DATE_FORMAT(dateofcompletion,'%Y-%m') AS month
FROM `jobdetails`
WHERE jobstatus='complete'
GROUP BY DATE_FORMAT(dateofcompletion,'%Y-%m')");
while($result = $query->fetch_object()) {
echo '<div style="float:right; padding-right:10px;">';
echo '<strong>Work Complete Totals</strong>';
$month = $result->dateofcompletion;
$pricequoted = number_format($result->pricequotedtotal, 2, '.', '');
$partprice = number_format($result->partpricetotal, 2, '.', '');
$profit = number_format($result->profittotal, 2, '.', '');
echo 'month:'.$month;
echo '<p><strong style="color:red;">Quoted Total : £'.$pricequoted.'</strong></p>';
echo '<p><strong style="color:Darkorange ;">Parts Total : £'.$partprice.'</strong></p>';
echo '<p><strong style="color:green;">Profit Total : £'.$profit.'</strong></p>';
}
echo '</div>';
//////////////////////////////////////////////////////
答案 0 :(得分:2)
在查询中进行小修改
$query = $db->query("SELECT
MONTHNAME(dateofcompletion) AS dateofcompletion,
SUM(pricequoted) AS pricequotedtotal,
SUM(partprice) AS partpricetotal,
SUM(profit) AS profittotal,
DATE_FORMAT(dateofcompletion,'%Y-%m') AS month
FROM `jobdetails`
WHERE jobstatus='complete'
GROUP BY DATE_FORMAT(dateofcompletion,'%Y-%m')");
这应该有用。