Hi
I've a Mysql table with the following fields Ext, Elapse and Cost:
Ext Elapse Cost
236 5 150
206 1 30
222 5 150
220 2 60
223 3 90
236 2 60
236 2 60
210 4 120
223 3 90
I need to totalize the Elapse and Cost according to the field Ext, but I need to see every register for Ext, Something like this:
Ext Elapse Cost
206 1 30
Total 1 30
210 4 120
Total 4 120
220 2 60
Total 2 60
222 5 150
Total 5 150
223 3 90
223 3 90
Total 6 180
236 5 150
236 2 60
236 2 60
Total 9 270
Using GROUP BY I can totalize the fields Elapse and Cost according to Ext but I can't see every register for Ext:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("calls", $con);
// Construct our join query
$query = "SELECT Ext, SUM(elapse) AS TotalElapse, SUM(cost) AS TotalCost ".
"FROM register ".
"GROUP BY Ext ORDER BY Ext";
$result = mysql_query($query) or die(mysql_error());
// Print out the contents of each row into a table
while($row = mysql_fetch_array($result)){
echo $row['Ext']. " - ". $row[' TotalElapse ']. " - ". $row[' TotalCost '];
echo "<br />";
}
?>
This is the output from the above program:
Ext TotalElapse TotalCost
206 1 30
210 4 120
220 2 60
222 8 150
223 6 180
236 9 270
Any Idea, Please?
I've a Mysql table with the following fields Ext, Elapse and Cost:
Ext Elapse Cost
236 5 150
206 1 30
222 5 150
220 2 60
223 3 90
236 2 60
236 2 60
210 4 120
223 3 90
I need to totalize the Elapse and Cost according to the field Ext, but I need to see every register for Ext, Something like this:
Ext Elapse Cost
206 1 30
Total 1 30
210 4 120
Total 4 120
220 2 60
Total 2 60
222 5 150
Total 5 150
223 3 90
223 3 90
Total 6 180
236 5 150
236 2 60
236 2 60
Total 9 270
Using GROUP BY I can totalize the fields Elapse and Cost according to Ext but I can't see every register for Ext:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("calls", $con);
// Construct our join query
$query = "SELECT Ext, SUM(elapse) AS TotalElapse, SUM(cost) AS TotalCost ".
"FROM register ".
"GROUP BY Ext ORDER BY Ext";
$result = mysql_query($query) or die(mysql_error());
// Print out the contents of each row into a table
while($row = mysql_fetch_array($result)){
echo $row['Ext']. " - ". $row[' TotalElapse ']. " - ". $row[' TotalCost '];
echo "<br />";
}
?>
This is the output from the above program:
Ext TotalElapse TotalCost
206 1 30
210 4 120
220 2 60
222 8 150
223 6 180
236 9 270
Any Idea, Please?