Forum Moderators: coopster

Message Too Old, No Replies

Performing math functions on array elements

         

Shaman13

9:11 pm on Dec 3, 2004 (gmt 0)

10+ Year Member



Does anyone know how to add up values in an array to display their total? I am using a query that builds the array below. I am looking for some way to add the values in the row['TTIME'] to generate a total. It would also be nice to group the records display by [TIDATE] and display a total for each day. This is way over my head! Hoping that someone can at least point me in the right direction. Many Thanks!

for ($index = 0; $index < 5; $index++)

while($row=mysql_fetch_array($result)) {
print '<tr><td>'.$row['TIDATE'].'</td><td>'.$row['TTIME']. '</td><td>'.$row['REASON'].'</td><td>'.$row['CASENUM']. '</td><td>'.$row['FUNDSNUM'].'</td><td>'.$row['NONCASE']. '</td><td>'.$row['TIMEACTIVITY'].'</td><td>'.$row['SNUM']. '</td><TD><a href="time_edit.php? TIMEID='.$row['TIMEID'].'">Edit Time</a></td></tr>';
}

?>

[edited by: jatar_k at 11:11 pm (utc) on Dec. 3, 2004]
[edit reason] fixed sidescroll [/edit]

baze22

11:32 pm on Dec 3, 2004 (gmt 0)

10+ Year Member



I haven't tested what I did here but you should end up with an array of totals:


$myrows = array();
while($row=mysql_fetch_array($result)) {
$dateidx = $row['TIDATE'];
$myrows[$dateidx] += $row['TTIME'];
print '<tr><td>'.$row['TIDATE'].'</td><td>'.$row['TTIME']. '</td><td>'.$row['REASON'].'</td><td>'.$row['CASENUM']. '</td><td>'.$row['FUNDSNUM'].'</td><td>'.$row['NONCASE']. '</td><td>'.$row['TIMEACTIVITY'].'</td><td>'.$row['SNUM']. '</td><TD><a href="time_edit.php? TIMEID='.$row['TIMEID'].'">Edit Time</a></td></tr>';
}

baze