Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

sum function results


Go to End


757 Views

Avatar
voodoochile

Community Member, 52 Posts

23 August 2012 at 2:43pm

Hi

i have the following function

 function ProductPrice() {
	
              $sqlQuery = new SQLQuery( 
               "Recipe.Weight * Product.CostPrice", //  Select 
     	"Recipe, Product", // From 
	"Product.ID = " . $this->ProductID
	 );
	 
    	$Price = $sqlQuery->execute()->value();

               return $Price;	
				
            }

this works a treat and does exactly what i want, my problem is i am trying to sum the results of this as their are several products per recipe i only want the sum of $Price for a particuar recipe.

i have tried the following but think it needs more as i want it to loop through based on the recipe ID and the array_sum may be wrong as well.

 

function TotalProductPrice() {
	
	
	$tpp = array($this->ProductPrice());
	foreach($tpp as $tpps);
	
	 return array_sum( $tpps);
	
}

any help is appreciated