I am fetching some information from mysql database and I am displaying it using the following script(I am using Codeigniter)
<?php if(count($records) > 0) { ?>
<?php $i = $this->uri->segment(3) + 0; foreach ($records as $row){ $i++; ?>
<?php echo $row['amount']; ?> <br>
<?php } ?>
<?php } else { echo "No Record Found";} ?>
The out put I get is like following
10,000
20,000.34
15,250.50
Now what I am trying to do is sum up all the values that are in $row['amount']; and put the value of the summation in $sum_value so that when I echo $sum_value I get the following value
45,250.84
Would you please kindly show me how to do it.
I know I could have done the summation things using mysql, but I want to learn how to do this way.
Thanks in Advance 🙂
Iteratively add to your sum with each loop through the foreach: