0

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

    // 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>';
    //////////////////////////////////////////////////////
4

1 回答 1

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

这应该有效。

于 2013-05-29T10:09:30.063 回答