计算行总数

时间:2013-03-17 05:24:19

标签: php mysql

我从数据库中获取和显示记录

SELECT purchorders.orderno,
                    suppliers.suppname,
                    purchorders.orddate,
                    purchorders.deliverydate,
                    purchorders.initiator,
                    purchorders.requisitionno,
                    purchorders.allowprint,
                    purchorders.status,
                    suppliers.currcode,
                    currencies.decimalplaces AS currdecimalplaces,
                    SUM(purchorderdetails.unitprice*purchorderdetails.quantityord) AS ordervalue
                FROM purchorders 
                INNER JOIN purchorderdetails 
                ON purchorders.orderno = purchorderdetails.orderno
                INNER JOIN suppliers
                ON purchorders.supplierno = suppliers.supplierid
                INNER JOIN currencies 
                ON suppliers.currcode=currencies.currabrev
                WHERE purchorders.orderno=purchorderdetails.orderno
                GROUP BY purchorders.orderno,
                    suppliers.suppname,
                    purchorders.orddate,
                    purchorders.initiator,
                    purchorders.requisitionno,
                    purchorders.allowprint,
                    purchorders.status,
                    suppliers.currcode,
                    currencies.decimalplaces LIMIT 5

我正确地得到了结果。但我想计算并显示我显示的订单价值的结果(总共5个,因为我将它限制为5个)

我试过这样做

$SalesOrdersResult2 = DB_query($SQL,$db);
while ($row = DB_fetch_array($SalesOrdersResult2))
{
$FormatedOrderValue2 = locale_number_format($row['ordervalue'],$row['currdecimalplaces']);
$Total = $array_sum($row['ordervalue']);
$FormatedOrderDate1 = ConvertSQLDate($row['orddate']);
                        $FormatedDelDate1 = ConvertSQLDate($row['deliverydate']);

                        echo " <tr><td> " . $row['suppname'] . " </td>";
                        echo " <td>$FormatedOrderDate1</td><td>$FormatedDelDate1</td><td> " . $row['initiator'] . " </td><td>$FormatedOrderValue2</td><td> " . $row['status'] . " </td></tr> ";

                    }
        echo "<tr><td colspan='3'>Total---</td><td colspan='2'>$Total</td></tr></tbody>";

但它说“致命错误:函数名称必须是...中的字符串”

有人请帮我这样做 感谢

2 个答案:

答案 0 :(得分:0)

删除$之前的array_sum

答案 1 :(得分:0)

我怀疑你是在尝试做这样的事情?:

$SalesOrdersResult2 = DB_query($SQL, $db);
$Total = 0;
while ($row = DB_fetch_array($SalesOrdersResult2))
{
    $FormatedOrderValue2 = locale_number_format($row['ordervalue'],$row['currdecimalplaces']);
    $Total += $row['ordervalue'];
    $FormatedOrderDate1 = ConvertSQLDate($row['orddate']);
    $FormatedDelDate1 = ConvertSQLDate($row['deliverydate']);
    echo " <tr><td> " . $row['suppname'] . " </td>";
    echo " <td>$FormatedOrderDate1</td><td>$FormatedDelDate1</td><td> " . $row['initiator'] . " </td><td>$FormatedOrderValue2</td><td> " . $row['status'] . " </td></tr> ";
}
echo "<tr><td colspan='3'>Total---</td><td colspan='2'>$Total</td></tr></tbody>";