Sum of a datasheet

Author Message

Pierre Rigal

Saturday 19 March 2005 9:23:23 am

Hello !

Firstly excuse my poor english, i'm french ;)
So this is my code :

{let page_limit=20
children=fetch('content','list',hash(parent_node_id,$node.node_id,sort_by,$node.sort_array,limit,$page_limit,offset,$view_parameters.offset))    list_count=fetch('content','list_count',hash(parent_node_id,$node.node_id))
nous=0
eux=0}
<p>
<table>
<th>Map</th><th>Score</th>
{section name=Child loop=$children sequence=array(bglight,bgdark)}
<tr>
{set nous=sum($nous,$Child:item.object.data_map.partie_scorenous.content)}
{set eux=sum($eux,$Child:item.object.data_map.partie_scoreadv.content)}

{node_view_gui view=line content_node=$Child:item}
</tr>
{/section}
<tr><td>Total :</td><td> {$nous} -{$eux}  </td><tr>
</table>
</p>
{/let}

It succesfully displays an HTML array of matches and scores like that :
Match | Scores
match1 | <b>1</b>-0
match2 | 3-2
etc.
Each part of the score is an integer.
This line :

{node_view_gui view=line content_node=$Child:item}

shows a score (eg 1-0)
This code :

$Child:item.object.data_map.partie_scorenous.content

can access to a part of the score ( eg in bold in the above array : 1 )

My problem is to display the final result of the array :

<tr><td>Total :</td><td> {$nous} -{$eux}  </td><tr>

using these lines to calculate the sum of each side of the score :

{set nous=sum($nous,$Child:item.object.data_map.partie_scorenous.content)}
{set eux=sum($eux,$Child:item.object.data_map.partie_scoreadv.content)}

But it doesn't work ...
What is wrong ?
Thanks...

Łukasz Serwatka

Sunday 20 March 2005 11:03:47 pm

Hi Pierre,

This was a namespace problem. I recommend to use var= instead of name= in sections.

Example with var=

{let page_limit=20
children=fetch('content','list',hash(parent_node_id,$node.node_id,sort_by,$node.sort_array,limit,$page_limit,offset,$view_parameters.offset))    list_count=fetch('content','list_count',hash(parent_node_id,$node.node_id))
nous=0
eux=0}
<p>
<table>
<th>Map</th><th>Score</th>
{section var=Child loop=$children sequence=array(bglight,bgdark)}
<tr>
{set nous=sum($nous,$Child.object.data_map.partie_scorenous.content)}
{set eux=sum($eux,$Child.object.data_map.partie_scoreadv.content)}

{node_view_gui view=line content_node=$Child}
</tr>
{/section}
<tr><td>Total :</td><td> {$nous} -{$eux}  </td><tr>
</table>
</p>
{/let}

Example with name=

{let page_limit=20
children=fetch('content','list',hash(parent_node_id,$node.node_id,sort_by,$node.sort_array,limit,$page_limit,offset,$view_parameters.offset))    list_count=fetch('content','list_count',hash(parent_node_id,$node.node_id))
nous=0
eux=0}
<p>
<table>
<th>Map</th><th>Score</th>
{section name=Child loop=$children sequence=array(bglight,bgdark)}
<tr>
{set nous=sum($Child:nous,$Child:item.object.data_map.partie_scorenous.content)}
{set eux=sum($Child:eux,$Child:item.object.data_map.partie_scoreadv.content)}

{node_view_gui view=line content_node=$Child:item}
</tr>
{/section}
<tr><td>Total :</td><td> {$Child:nous} -{$Child:eux}  </td><tr>
</table>
</p>
{/let}

I hope it will help.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Pierre Rigal

Thursday 31 March 2005 2:21:35 pm

Really, really thanks !
It works fine !

Łukasz Serwatka

Thursday 31 March 2005 9:18:09 pm

You`re welcome! :)

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.