Jump to content

Foreach Adding up


gum1982

Recommended Posts

 

Hello can someone please help me im running a foreach loop that is pulling the prices value out off my database as follows.

 

this is the function

function one_life()
{
  db_connect();

	$query = "SELECT * FROM paypal_payment_info order by paypal_payment_info.mc_gross DESC";

	$result = mysql_query($query);

	if(!$result)
{
	echo mysql_error();
}

	$result = db_result_to_array($result);

	return $result;
}

$one_lifes = one_life(); 

 

This is my foreach loop

<?php foreach($one_lifes as $one_life) { ?>
        <?php echo $one_life['mc_gross']; ?> 
<?php } ?>

 

So this gives me the values i have a list like this.

 

200 10 30 200 350

 

What i need to do is add all these values together and echo one overall amount which would be say 790 for the example.

 

Any Help Please?

 

Link to comment
https://forums.phpfreaks.com/topic/190525-foreach-adding-up/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.