Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Recursive loops?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
furious5
Smarty Rookie


Joined: 06 Sep 2004
Posts: 16

PostPosted: Tue Dec 14, 2004 5:17 pm    Post subject: Recursive loops? Reply with quote

Can anyone help me out, I've written some code in a smarty template to use the key of the previous foreach statement to drill down to the index I require.

I have a problem where my second assigned key (g_key) is not being reset and therefore I am having some results stripped off for instance if I have an array index[1], with 15 elements in it, when I move on to index[2] with 15 elements in I only get the last element as the g_key is being held at a value of 15 from the previous iteration through index[1] - if this makes sense.

I really need to use key, as I have assigned my arrays using associative keys so some may start from 1, 2 or 3 as opposed to 0.

Does anyone know how I can go about amending my code to loop from the beginning of the next array dimension???

Code:

{foreach key=c_key item=course from=$courses}
      <p>{$course.course_name}</p>
      <table width="100%" class="grouping" cellspacing="0" cellpadding="2">
         <tr class="title">
            <th class="groupno">Group</th>
            <th class="tee_off">Tee Off</th>
            <th class="start">Hole</th>
            <th class="players">Player 1</th>
            <th class="players">Player 2</th>
            <th class="players">Player 3</th>
         </tr>
         {foreach key=g_key item=group from=$groups[$c_key]}
         <tr class="{cycle values="leader_lightrow, leader_darkrow"}">
            <td class="groupno">{$group.groupno}</td>
            <td class="tee_off">{$group.tee_off_time|date_format:"%H:%M %p"}</td>
            <td class="start">{$group.starthole}</td>
            {foreach name=player_count item=player from=$players[$c_key][$g_key]}
            <td class="players">{$player}</td>
            {/foreach}
         
            {* If the table cells are less than three, loop through until these are equal to 3*}      
            {if $smarty.foreach.player_count.total < 3} 
               {section name=extra_player start=$smarty.foreach.player_count.total loop=3}
               <td class="players"></td>
               {/section}
            {/if}
         </tr>
         {/foreach}
      </table>
      {/foreach}


Last edited by furious5 on Sun May 02, 2010 9:51 pm; edited 1 time in total
Back to top
View user's profile Send private message
furious5
Smarty Rookie


Joined: 06 Sep 2004
Posts: 16

PostPosted: Wed Dec 15, 2004 12:09 pm    Post subject: Reply with quote

Its ok, there was nothing wrong with my smarty code, it was with the array I was trying to join on which had not been set correctly in PHP.
________
Ford Mustang SSP specifications
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP