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.

eZ debug

Timing: Jan 18 2025 18:33:32
Script start
Timing: Jan 18 2025 18:33:32
Module start 'layout'
Timing: Jan 18 2025 18:33:32
Module start 'content'
Timing: Jan 18 2025 18:33:33
Module end 'content'
Timing: Jan 18 2025 18:33:33
Script end

Main resources:

Total runtime0.7883 sec
Peak memory usage4,096.0000 KB
Database Queries60

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0050 587.8906152.6094
Module start 'layout' 0.00500.0028 740.500039.4141
Module start 'content' 0.00780.7791 779.9141564.7422
Module end 'content' 0.78700.0013 1,344.656316.1875
Script end 0.7883  1,360.8438 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00290.3682160.0002
Check MTime0.00120.1559160.0001
Mysql Total
Database connection0.00070.093910.0007
Mysqli_queries0.733893.0878600.0122
Looping result0.00060.0742580.0000
Template Total0.761896.620.3809
Template load0.00170.220520.0009
Template processing0.760196.424920.3800
Template load and register function0.00020.020410.0002
states
state_id_array0.00080.099610.0008
state_identifier_array0.00070.086520.0003
Override
Cache load0.00150.1899410.0000
Sytem overhead
Fetch class attribute can translate value0.00060.073220.0003
Fetch class attribute name0.00100.128450.0002
XML
Image XML parsing0.00070.088820.0004
class_abstraction
Instantiating content class attribute0.00000.001860.0000
General
dbfile0.00090.1089180.0000
String conversion0.00000.001340.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
12content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
7content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 32
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs