Working with data in a Loop

Author Message

Matt Dorn

Monday 27 October 2003 1:40:08 am

Maybe somebody can help me.

As a Web developer on other platforms, I've been in many situations where it made sense to sort data on the basis of some category field, then display the data broken down by that category.

For example, let's say I have a 5-record result set that looks like this:

Company: Productos AC
Country: Spain

Company: ABC, Inc.
Country: U.S.

Company: XYZ Gmbh.
Country: Germany

Company: Acme Enterprises
Country: U.S.

Company: Gonzales, SA
Country: Spain

Now, if I return this data sorted by country, in a language like PHP I could create a loop, and store the country name in a buffer variable before moving to the next iteration, then I'd compare the buffer country value to the current country value, and if it's different, create a delimiter (---------) in the display. So the output would look like this:

XYZ Gmbh. - Germany
------------
Gonzales SA - Spain
Productos AC - Spain
------------
ABC Inc. - U.S.
Acme Enteprises - U.S.

In EZPublish, while I can sort the data appropriately, it seems I don't have enough control within the looping structure to accomplish this.

I have a loop that looks like this:


    {section name=Child loop=fetch(content, list, hash( 
        parent_node_id, $node.node_id,
        limit, $page_limit,
        offset, $view_parameters.offset,
        sort_by,array(array('attribute',true(),215)),
        class_filter_type, include, 
        class_filter_array, array( 18 ) ) )}
        
        $Child:item.data_map.country.data_text}
        
    {/section}

Is there anything I can do here to accomplish my goal?

Vivienne van Velzen

Monday 27 October 2003 3:46:38 am

Hi Matt,

Couldn't you do something like this:

{let name=myroot
     mytext=""
}
{section loop=fetch...}
    {section show=$myroot:mytext|ne($:item.attribute)}
        ----------<br>
    {/section}
    {$:item.data_map.country.data_text}<br>
    {set mytext=$:item.attribute}
{/section}
{/let}

Where $mytext is the buffer variable you mentioned. Note that I moved the namespace (the section no longer has a name, the surrounding let has), so the 'set' function works.
Hope this helps,

Vivienne

Matt Dorn

Monday 27 October 2003 9:38:05 am

Vivienne, you are a master! I guess my main problem was not knowing how to manipulate the namespace properly (I assumed you could nest them, and still be able to set the variables in the parent namespace).

Anyway, this works perfectly. Thanks so much for your help!

Matt

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 19 2025 04:36:02
Script start
Timing: Jan 19 2025 04:36:02
Module start 'layout'
Timing: Jan 19 2025 04:36:02
Module start 'content'
Timing: Jan 19 2025 04:36:03
Module end 'content'
Timing: Jan 19 2025 04:36:03
Script end

Main resources:

Total runtime0.6485 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0084 589.1563152.6250
Module start 'layout' 0.00840.0038 741.781339.4453
Module start 'content' 0.01220.6351 781.2266480.3438
Module end 'content' 0.64730.0012 1,261.570312.1641
Script end 0.6485  1,273.7344 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.5498160.0002
Check MTime0.00140.2234160.0001
Mysql Total
Database connection0.00160.252710.0016
Mysqli_queries0.591191.1524570.0104
Looping result0.00060.0862550.0000
Template Total0.615194.820.3075
Template load0.00190.289420.0009
Template processing0.613294.552620.3066
Template load and register function0.00020.036510.0002
states
state_id_array0.00100.159910.0010
state_identifier_array0.00130.200020.0006
Override
Cache load0.00160.2503390.0000
Sytem overhead
Fetch class attribute can translate value0.00070.108520.0004
Fetch class attribute name0.00120.179030.0004
XML
Image XML parsing0.00030.048620.0002
class_abstraction
Instantiating content class attribute0.00000.001630.0000
General
dbfile0.00080.1195100.0001
String conversion0.00000.001540.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
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 25
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs