0

Im trying to figure out the best wasy to loop over an array, but limit one loop to the first five positions. Then in a separate loop display the rest of the array.

I am limited to what I can use. Meaning we code everything within cfscript tags in our cfc's. Therefore I cant use cfsets or such.
Here is my cfloop now:

<cfloop from="1" to="#variables.albumEdit.albumCnt#" index="i">
        <li id="article_1"><input type="hidden" name="trackList" value="#variables.albumEdit.albumName[i]#" />
        <span class="attribute album-title">#variables.albumEdit.albumName[i]#</span>
        <span class="attribute album-status">#variables.albumEdit.prodStatus[i]#</span><cfloop from="1" to="#variables.albumEdit.albumCnt#" index="i">
        <li id="article_1"><input type="hidden" name="trackList" value="#variables.albumEdit.albumName[i]#" />
        <span class="attribute album-title">#variables.albumEdit.albumName[i]#</span>
        <span class="attribute album-status">#variables.albumEdit.prodStatus[i]#</span>
        <span class="attribute genre">Rock</span>
        <span class="attribute release-date">#variables.albumEdit.releaseDate[i]#</span>
        <span class="attribute track-list"><a href="index.cfm?action=younger.trackListEdit&prodID=#variables.albumEdit.prodID[i]#">Edit Tracks</a></span>
      <div class="controls">
         <a class="button secondary" href="index.cfm?action=younger.gcaAlbumDetailEdit&prodID=#variables.albumEdit.prodID[i]#">Edit</a>
      </div>
      </li>
      </cfloop>
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by arrgh
0

ok I tried editing this to add additional info. I need to loop over the first 5 arrays, then have another loop to output any remaining data greater than 5. Thanks for any help.

0

I need to loop over the first 5 arrays, then have another loop to output any remaining data greater than 5

If you elements, can't you just loop twice? Loop from 1-5, if there are enough elements

   <cfset firstLoopMax = Min(variables.albumEdit.albumCnt, 5)>
   <cfset lastShownIndex  = 1>
   <cfloop from="1" to="#firstLoopMax#" index="i">       
       ... show element ...
       <!--- track displayed index --->
       <cfset lastShownIndex = lastShownIndex + 1>
   </cfloop>

Then loop again to show the remaining elements

   <cfloop from="#lastShownIndex#" to="#variables.albumEdit.albumCnt#" index="i">       
       ... show element ...
   </cfloop>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.