gpt4 book ai didi

php - 将月份名称添加到每月总计中

转载 作者:行者123 更新时间:2023-11-29 08:30:18 26 4
gpt4 key购买 nike

我正在使用以下方法来计算我的每月总计,它工作得很好,但我试图在每个总计的顶部获取每个月的名称,但我目前得到的只是月份:没有别的。

    // 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 : &pound;'.$pricequoted.'</strong></p>';
echo '<p><strong style="color:Darkorange ;">Parts Total : &pound;'.$partprice.'</strong></p>';
echo '<p><strong style="color:green;">Profit Total : &pound;'.$profit.'</strong></p>';
}

echo '</div>';
//////////////////////////////////////////////////////

最佳答案

对查询进行小修改

    $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')");

这应该有效。

关于php - 将月份名称添加到每月总计中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16811027/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com