Share » Forums » Setup & design » adding up the value of one specific...

adding up the value of one specific attribute of all the children in one node

adding up the value of one specific attribute of all the children in one node

Monday 26 April 2004 4:10:21 am - 3 replies

Modified on Monday 26 April 2004 4:13:52 am by Nicolas Heiringhoff

Author Message

Balazs Halasy

Monday 26 April 2004 4:36:49 am

Look at the code that is presented here:

http://ez.no/ez_publish/documentation/building_an_ez_publish_site/the_guestbook/creating_the_template

Feel free to copy & use it. If so: change the line that says

{set counter=$:counter|inc}

to something like this:

{set counter=$:counter|sum($:item.object.data_map.umsatz)}

Balazs

Nicolas Heiringhoff

Monday 26 April 2004 6:05:34 am

we have modified the code the way you suggested:


{* Grab all the guestbook entries. *}
{let name=test counter=0 children=fetch( content,
                                         list,
                                         hash( parent_node_id,
                                               $node.node_id,
                                               sort_by,
                                               $node.sort_array
                                             )
                                        )
                                       
                                        
}
 Value of counter at this point: {$:counter}<br />
 
<table>

{* Loop through all the entries. *}
{section loop=$:children}
<br />
    {* Increment the counter by one. *}
    
{set counter=$:counter|sum($:item.object.data_map.umsatz)}   


<tr><td>

        Umsatz value: <i>{$:item.object.data_map.umsatz.content|wash}</i>
    </td></tr>

{* End of loop. *}
{/section}

    <tr><td><hr /></td></tr>
</table>

<div class="center">
    total Umsatz: {$:counter}
</div>

{* Release the counter and the children variable. *}
{/let}

It returns the values of the 4 objects of the class "frabo" in node 47:
Umsatz value: 1

Umsatz value: 12500

Umsatz value: 20000

Umsatz value: 500000

but wenn the code should return the sum of the "total umsatz" , it returns:

total Umsatz: 24

now that is rather strange, because all we don?t know where this value '24' comes from.
the total umsatz should add up to 532 501.

http://www.heiringhoff.de

Nicolas Heiringhoff

Wednesday 28 April 2004 6:54:33 am

After two days we finally got it:

{let counter=0}
	
			{let nodes=fetch( 'content', 'tree', hash( 'parent_node_id', 47 ) ) }
        	{section loop=$nodes}
        
			{set counter=$:counter|sum($:item.data_map.umsatz.data_int,$counter)}		
			

			{/let}
	
			{/section}
			
<!-- hier wird das Ergebnis ausgegeben-->

			{$counter}
			
<!-- hier wird das Ergebnis ausgegeben-->
{/let}

http://www.heiringhoff.de

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu