Share » Forums » Setup & design » Counting in a loop and getting the...

Counting in a loop and getting the value back

Counting in a loop and getting the value back

Friday 03 March 2006 1:37:15 am - 2 replies

Modified on Friday 03 March 2006 1:37:59 am by J-A Eberhard

Author Message

Nabil Alimi

Thursday 09 March 2006 9:03:28 am

Hi J-A,

What about using a simple counter ?

This could work that way :

{$question.question_number}. {$question.text|wash('xhtml')}<br />


{$question.result_id}


 

{let result=fetch('survey', 'multiple_choice_result_item', 

                                                        hash( 'question', $question, 

                                                        'metadata', $metadata, 

                                                        'result_id', $result_id ))}


                                                        


  
<b>{def $counter=0}</b>

{section var=ans loop=$result}


        {if $ans['value']|ge( 10 )}

        <b>{* INCREMENTING THE COUNTER *}</b>
        {set scope=global $counter=inc( $counter )}

           <font color="#008000">{"correct"|i18n("design/gdp")}</font>  

   {else}


           <font color="#ff0000">{"wrong"|i18n("design/gdp")}</font>


        {/if}


        {section show=$ans['label']|wash('xhtml')|count_chars}{$ans['label']|wash('xhtml')}


        {/section}


        {delimiter}, {/delimiter}


{/section}

You have {$counter} correct(s) answers.

For example.

My blog : http://www.starnab.com/ezpublish / http://www.starnab.com/ / http://www.assiki-consulting.com
eZ Publish Freelance developper. Feel free to contact me +33 674 367 057
nabil at assiki d0t fr

J-A Eberhard

Monday 13 March 2006 12:46:56 pm

Thanks a lot.
I took another approach by rewriting the {section} into {foreach} loop to avoid the scope problem.

Open Source Solution Provider
Open-Net Ltd Switzerland
http://www.open-net.ch

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

36 542 Users on board!

Forums menu