We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,820 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

looping over arrays in two sections

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 Days
Discussion Span
10 Months Ago
Last Updated
3
Views
teedoff
Practically a Master Poster
605 posts since Jul 2010
Reputation Points: 21
Solved Threads: 60
Skill Endorsements: 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.

teedoff
Practically a Master Poster
605 posts since Jul 2010
Reputation Points: 21
Solved Threads: 60
Skill Endorsements: 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>
arrgh
Posting Pro in Training
405 posts since Dec 2008
Reputation Points: 32
Solved Threads: 50
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.5086 seconds using 2.51MB