• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to repeat a column header every 10 or 20 rows?

Contributor ,
Feb 05, 2008 Feb 05, 2008

Copy link to clipboard

Copied

Does anyone know how to display a row which includes column header information every 10 or 20 rows in a table? This is in a basic .cfm page.
TOPICS
Advanced techniques

Views

708

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Feb 06, 2008 Feb 06, 2008
Ahh.. figured out my problem.. I need to use currentRow. instead of recordCount. Here's a great little page on Mod... http://tutorial140.easycfm.com/

Votes

Translate

Translate
LEGEND ,
Feb 05, 2008 Feb 05, 2008

Copy link to clipboard

Copied

if the modulus of your loop index or query.currentrow and 10 is 0, write your column headers.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 05, 2008 Feb 05, 2008

Copy link to clipboard

Copied

How do I tell it to display the header on row 10, 20, 30, 40, etc? Need to increment it every 10rows...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 05, 2008 Feb 05, 2008

Copy link to clipboard

Copied

Use the modulus operator. What it does is return the remainder when you do division:-

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 06, 2008 Feb 06, 2008

Copy link to clipboard

Copied

The problem I'm having is that the sql query returns 22 records, and the loop doesn't seem to start at one, count up to ten and display a row. Here's my code....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 05, 2008 Feb 05, 2008

Copy link to clipboard

Copied

Lucky Kitty wrote:
> How do I tell it to display the header on row 10, 20, 30, 40, etc? Need to increment it every 10rows...

Understand the modules 'mod' operator. This is the companion division
'/' operator. It returns the reminder of a division. If the remainder
of a division is zero the numerator was evenly divided by divisor. Thus
every time rowNum mod 10 EQ 0, the row is evenly divided by 10, i.e. 10,
20, 30, 40, ect., and you can do something.

<cfoutput>
<cfloop from="1" to="55" index="i">
#i#
<cfif i mod 10 EQ 0>
- 10th row, do something like a header
</cfif>
<br>
</cfloop
</cfoutput>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 06, 2008 Feb 06, 2008

Copy link to clipboard

Copied

Ahh.. figured out my problem.. I need to use currentRow. instead of recordCount. Here's a great little page on Mod... http://tutorial140.easycfm.com/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 06, 2008 Feb 06, 2008

Copy link to clipboard

Copied

LATEST
Lucky Kitty wrote:
> Ahh.. figured out my problem.. I need to use currentRow. instead of recordCount. Here's a great little page on Mod... http://tutorial140.easycfm.com/

Nice explanation of the MOD operator, but the example is a bit
cumbersome. I would simplify it thusly:

<table border=”1”>
<tr>
<cfoutput query=”getFoo”>
<td>#getFoo.currentRow#</td>
<cfif getFoo.currentRow MOD 4 EQ 0>
</tr>
<tr>
</cfif>
</cfoutput>
</tr>
</table>

Unless you are being very picky about spacing you can simple close the
current row and start the next row inside the MOD if statement.
Eliminates the need for an extra boolean variable, if statement and else
clause.




Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation