logo       

Re: [SMARTY] Any way to add values in a loop?: msg#00421

php.smarty.general

Subject: Re: [SMARTY] Any way to add values in a loop?

You'd be better off supplying the sum as an assigned variable. It is
much faster to do the math in PHP with array_sum(), and doing math
shouldn't really be a duty of the template.

But saying that, you can do it if you want. Put this in your loop:

{math equation="x+y" x=$total y=$loopvar assign="total"}

Monte

On Wed, 2003-01-29 at 09:58, m guckeyson wrote:
> Basically, I'd like to add up all the values of a foreach and display the
> total after all the values are printed out as rows. I seem to recall seeing
> a mechanism for doing this, but I can't find it now. Anyone able to jog my
> memory?


--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise