Forums / Setup & design / Working with data in a Loop

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

eZ debug

Timing: Jan 20 2025 01:10:57
Script start
Timing: Jan 20 2025 01:10:57
Module start 'content'
Timing: Jan 20 2025 01:10:57
Module end 'content'
Timing: Jan 20 2025 01:10:58
Script end

Main resources:

Total runtime1.0755 sec
Peak memory usage4,096.0000 KB
Database Queries194

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0072 588.9531180.8359
Module start 'content' 0.00720.8722 769.7891485.4219
Module end 'content' 0.87940.1960 1,255.2109333.4766
Script end 1.0754  1,588.6875 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00430.3968210.0002
Check MTime0.00160.1463210.0001
Mysql Total
Database connection0.00080.076910.0008
Mysqli_queries0.987391.80521940.0051
Looping result0.00260.23741920.0000
Template Total1.044397.120.5222
Template load0.00180.171220.0009
Template processing1.042596.931420.5212
Template load and register function0.00020.015710.0002
states
state_id_array0.00140.126310.0014
state_identifier_array0.00100.092220.0005
Override
Cache load0.00160.1451390.0000
Sytem overhead
Fetch class attribute can translate value0.00190.181230.0006
Fetch class attribute name0.00110.101430.0004
XML
Image XML parsing0.00050.049630.0002
class_abstraction
Instantiating content class attribute0.00000.000730.0000
General
dbfile0.01551.4380210.0007
String conversion0.00000.000630.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 25
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs