我想计算具有相同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