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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.