Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cfloop and table data 1

Status
Not open for further replies.

aliashippysmom

Programmer
Jul 29, 2004
43
US
Hi! I have a problem which is something I can't quite figure out. I have a two part form. The user enters a number on the first form and hits SUBMIT. Based on that number, an input table is generated on the second form. If we assume the user enters 7 for the number of items, the input table on the second screen would look like this. I need a maximum of 6 items per line. txt is a input of type text and chk is input of type checkbox. The user will enter values across the page for each Call Center.

Call Center # 1 2 3 4 5 6
Call Center Loc txt txt txt txt txt txt
Virtual chk chk chk chk chk chk

Call Center # 7
Call Center Loc txt
Virtual chk

Here's my test code so far:
Code:
<cfset numitems = 10>  NUMBER OF ITEMS FROM FIRST FORM
<cfset remainder = numitems MOD 6>
<cfset total = numitems>
<cfset flag = 0>

<cfset num1 = 1>
<cfset num2 = 1>

<cfset r = min(#numitems#,6)>
<cfloop condition="#numitems# GT 0">
   <table>
   <tr><td>Call Center #</td>
  	  <cfloop index="j" from="#num1#" to="#r#">
	  	     <td><cfoutput>#j#</cfoutput></td>
  	  </cfloop>
	  </tr>
	  <tr><td>Call Center Location</td>
	  
	  <cfloop index="k" from="#num2#" to="#r#">
	  	     <td><cfoutput>#k#</cfoutput></td>
      	  </cfloop>
	  </tr>
	  </table>
	  
	  <cfset numitems = #numitems# - #r#>
	  <cfif numitems LT 0 and flag EQ 0>
	     <cfset numitems = remainder>
		 <cfset flag = 1>
          </cfif>		 
	  <cfoutput>Numitmes = #numitems#</cfoutput>
	  
	  <cfset num1 = num1 + 6>
	  <cfset num2 = num2 + 6>
	  <cfset r = r + #min(numitems,6)#>
	  <cfif r GT total>
	     <cfset r = remainder>
          </cfif>		
</cfloop>
I hope this makes some sense. It seems to work o.k. if the number of items is greater than 12. Can anyone help?
 
i didn't really investigate your code fully, but to maybe offer a simpler way of accomplishing this have a look at this example:

Code:
<cfset numItems = 10>   <!--- NUMBER OF ITEMS FROM FIRST FORM --->
<cfset maxRowItems = 6> <!--- NUMBER OF ITEMS TO DISPLAY ON EACH ROW --->

<cfoutput>

	<cfloop from="1" to="#numItems#" step="#maxRowItems#" index="rowCount">
		
		<cfset startSubLoopAt = rowCount>
		<cfset endSubLoopAt = startSubLoopAt + (maxRowItems - 1)>
		
		<cfloop from="#startSubLoopAt#" to="#endSubLoopAt#" index="ii">
		<cfif ii GT numItems>
			<cfbreak>
		</cfif>
		#ii# <!--- Show your content for each iteration --->
		</cfloop>
		<br>
	</cfloop>
	
</cfoutput>

=========================================
Don't sweat the petty things and don't pet the sweaty things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top