I am running a simple query and while loop:
$query = "select * from table1";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$plan_units = $row['plan_units'];
$plan_dollars = $row['plan_dollar'];
$division = $row['division];
$plan_units_total += $plan_units;
$plan_dollars_total += $plan_dollars;
}
The results display like:
division1 10 $40000
division1 30 $90000
division2 15 $52000
division2 18 $60000
Totals 73 $242000
What I'd like to do is get subtotals for each division. Now I know I could run a query for each division and simply run a total that way. But for various reasons, I'm trying to do this within one loop.
I'm currently using arrays that compare the current division name with the previous row's division name, so I know where the breaks are between divisions and I've set up the output table with sub-total rows in the right place.
I just can't figure out how to get a running total that reverts to zero at each break. I know this is probably simple, but I'm drawing a blank.
Thanks.