Jump to:

23454 Posts in 18904 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » sum function results

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

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

Page: 1
Go to End
Author Topic: 362 Views
  • voodoochile
    Avatar
    Community Member
    52 Posts

    sum function results Link to this post

    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

    362 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.