List of Topics

SfC Home > Web Design > SQL > ColdFusion >


Explanation of how to List Ten-at-a-Time from a ColdFusion Query. Key words: database, table, functions, if, then, CFIF, CFSET, session manager, School for Champions. Copyright © Restrictions

List Ten-at-a-Time from a ColdFusion Query

by Ron Kurtus (revised 3 July 2001)

You can list items from a database table with a common query. Even if you filter the results, you may get a long list of items. There is a method to list a select number of items at a time.

Questions you may have include:

This lesson will answer those questions.

First 10 items

Suppose you make a simple query.

<cfquery name="list_items" datasource="db_name">
select item
from my_tables
orderby itemID

To get the first 10 items, you set boundaries in your output.

<cfoutput query="list_items" startrow="1" maxrows="10">

Repeated method

To list the first 10 items and then be able to click on a link to repeatedly show the next 10, you could use the following code:


<CFQUERY NAME="list_items" DATASOURCE="db_name">
SELECT item FROM my_tables

<CFIF IsDefined("")>

<CFSET session.start = #session.start# + 10>

<P>List of next 10 items</P>

<CFOUTPUT QUERY="list_items" STARTROW="#session.start#" MAXROWS="10">

<P><A HREF="this_page.cfm?next=10">Next 10</A></P>


<P>List of first 10 items</P>

<CFSET start = 1>

<CFSET session.start = #start#>

<CFOUTPUT QUERY="list_items" STARTROW="#session.start#" MAXROWS="10">

<P><A HREF="this_page.cfm?next=10">Next 10</A></P>



You really want the whole application to be on one page. When you open the page, has not been defined, so you start at the <CFELSE> term.

Session management is used so that the variables that you set will be carried forward, when you click the link to go to the next view of this page.

The expression in the link: ?next=10 will send to the <CFIF> tag. "Next" could be set to equal anything. I used 10 just to indicate a list of 10 items.

In the <CFIF> section, the STARTROW is now the previous one plus 10.

To list a items other than 10 at a time, change the value of X in MAXROWS="X" and <CFSET session.start = #session.start# + X>.


This is an easy way to list the output of your query 10 items at a time. You can adjust it to list any number you wish.

Programming rocks

Resources and references

Ron Kurtus' Credentials


ColdFusion Resources


Top-rated books on ColdFusion

Questions and comments

Do you have any questions, comments, or opinions on this subject? If so, send an email with your feedback. I will try to get back to you as soon as possible.


Click on a button to bookmark or share this page through Twitter, Facebook, email, or other services:


Students and researchers

The Web address of this page is:

Please include it as a link on your website or as a reference in your report, document, or thesis.

Where are you now?

School for Champions

Web Design

ColdFusion topics

List Ten-at-a-Time from a ColdFusion Query

ColdFusion topics


Development methods

Specific applications

Also see

Let's make the world a better place

Be the best that you can be.

Use your knowledge and skills to help others succeed.

Don't be wasteful; protect our environment.

You CAN influence the world.

Live Your Life as a Champion:

Take care of your health

Seek knowledge and gain skills

Do excellent work

Be valuable to others

Have utmost character

Be a Champion!

The School for Champions helps you become the type of person who can be called a Champion.