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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output new row after 3 records 2

Status
Not open for further replies.

dv8er88

Programmer
Feb 21, 2005
42
US
Hello want to loop through a query and output a new row after 3 records.

Thanks D

<table width="95%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>record 1</td>
<td>record 3</td>
<td>record 3</td>
</tr>
<tr>
<td>record 4</td>
<td>record 5</td>
<td>record 6</td>
</tr>
<tr>
<td>record 7</td>
<td>record 8</td>
<td>record 9</td>
</tr>
</table>
 
Code:
<cfset i = 0 />

<table rules="all" border="1">
	<cfoutput query="myQuery" startrow="#i+1#">
		
		<cfif i MOD 3 IS 0>
			<tr>
		</cfif>
		
		<td>#myRecord#</td>
		<cfset i = i+1 />
		
		<cfif i MOD 3 IS 0>
			</tr>
		</cfif>
		
	</cfoutput>
</table>
 
One minor change to that ... the <cfif> statement that closes out the row should have another condition in case the query loop is over like so:

Code:
<cfif i MOD 3 EQ 0 OR i EQ myQuery.RecordCount>
 </tr>
</cfif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top