Hello.
I need some help with summing up the total price each company owe to us.
Basically it's looking like this currently:
http://i.imgur.com/7kkdt.png
For English speakers,
Företag = Company
Datum = Date
Artikel = Product
Antal = Amount
Pris = Price
And then the last row
Företag = Company
Total Summa = Total sum
The code for printing out the rows is currently looking like this:
$result = mysql_query("Select Customer.Customer_Company_Name,
Cleaning.Cleaning_Date,
Product.Product_Name,
CleaningRow.CleaningRow_Product_Amount,
CleaningRow.CleaningRow_Customer_Total_Price,
Cleaning.Cleaning_Invoice
From Cleaning Inner Join
CleaningRow On Cleaning.CleaningID = CleaningRow.CleaningID And
Cleaning.CustomerID = CleaningRow.CustomerID Inner Join
Product On CleaningRow.ProductID = Product.ProductID Inner Join
Customer On CleaningRow.CustomerID = Customer.CustomerID
Order By Customer.Customer_Company_Name");
printf ("<table>");
printf ("<tr>");
printf ("<td><b>Företag</b></td> <td><b>Datum</b></td> <td><b>Artikel</b></td> <td><b>Antal</b></td> <td><b>Pris</b></td>");
printf ("</tr>");
while($row = mysql_fetch_array($result))
{
printf("<tr>");
printf("<td>{$row['Customer_Company_Name']}</td> <td>{$row['Cleaning_Date']}</td> <td>{$row['Product_Name']}</td>
<td>{$row['CleaningRow_Product_Amount']}</td> <td>{$row['CleaningRow_Customer_Total_Price']}</td>");
printf("<br />");
printf("</tr>");
}
printf ("</table>");
Currently as you see it's only printing out the sum for that individual order.
What I want to print out in the last row is the total sum each company owes so something like:
Company --- Total Sum
Ericsson --- 402699 (395409 + 5985 + 1305 + 0 + 0)
IKEA --- 689100 (130500 + 558600)
SAAB --- 0 (0)
But I'm just not sure how to do this. If I store the numbers I get from CleaningRow_Customer_Total_Price in an array and sum them together I will have no clue what sum belongs to what company, and that's essentially the problem. Any help is appreciated and ask if something is unclear and I'll do my best to explain it better.