计算具有相同id的数据库中的值的总和

时间:2015-07-28 15:29:07

标签: php subtotal

我想计算具有相同id的amount_collected列的子总值和总值。这是我的代码:

<?php
        include 'includes/config/db_connection.php'; // include database connection 

                $sql = "SELECT DISTINCT(gmt_no) FROM driver_travel";
            $result = $db->query($sql);
            $errorInfo = $db->errorInfo();    
            echo  $error = $errorInfo[2];

            while($row = $result->fetch())
            {


          $sql1 = "SELECT Balance FROM driver_travel WHERE gmt_no =". $row['gmt_no'];
                $result1 = $db->query($sql1);
                $errorInfo = $db->errorInfo();    
                $error = $errorInfo[2];
                $gmtnocount = $result1->rowCount();         
                $gmtno[$gmtnocount] = Array();
                $bal[] = Array();
                $i = 0;                         
                    while($getrow = $result1->fetch())
                    {

                        echo $gmtnocount. " ";
                        $bal[$i] = $getrow['Balance']. "<p>"; 
                        $countbal = count($bal);
                            echo $countbal;
                        $i++; 
                        }
    }
?>

结果是 444455666

0 个答案:

没有答案