Gossamer Forum
Home : Products : Gossamer Links : Discussions :

How to calculate 2 fields?

Quote Reply
How to calculate 2 fields?
Using templates I can calculate this:

<%loop results%>
<%set total_count += $field1%>
<%endloop%>

and then display total like this:
Total: <%total_count%>
Angelic
Above works fine. Now I want to go little more advanced:
<%loop results%>
<%set total_count += $field1 * $field2%>
<%endloop%>

ie calculate by multiplying (field1 * field2) and then add them to 'total_count', until loop is finished.

now when displaying <%total_count%> there is nothing???

Why? and how do I correct this?Unsure
Thanks
Quote Reply
Re: [Suomi] How to calculate 2 fields? In reply to
I think you need to do this in more than one step. Something like this:
<%set temp = $field1%>
<%set temp *= $field2%><%set total_count += $temp%>