Creating NextPrev Link in Cold Fusion
(Page 1 of 3 )
Creating a Next/Prev link for query results in Cold Fusion is very easy with <cfloop> tag. Passing parameters to Start row and End row limits the record display in the specified range. Almost all of our database- driven applications require paging of query results. It might be handy if we had a custom tag or script written already. Just what we need is to extend that code wherever we want to place the paging and then change a few parameters. In this article, I show you how we can create Cold Fusion database query results with "Next 1 2 3 4... Prev" links.
Using <cfquery> tag
First we need to write a select statement to pull the data from the database. Cold Fusion uses <cfquery> tag to execute database commands. You may need to set up a data source name in the Cold Fusion administrator panel/ODBC Data sources to make a connection to the database. If you are using a shared server, you may ask your server administrator to set up one data source name for you.
I’m using a test table name called 'employee' to explain the paging example.
<!--- query for pulling employee details --->
<cfquery name="q_fetch" datasource="mydsn">
select id, name, dept from employee
</cfquery>
When we run this query through a Cold Fusion page it creates a query object with some return information. The return object consists of recordCount, currentRow and columnList variables. recordCount gives us the number of records returned by the query.
If you want to see the output of query results, use <cfdump var=”# q_fetch #”>. This <cfdump> tag is very useful for debugging purposes.
Next: Calculate the Offset and Limit Rows >>
More ColdFusion Articles
More By Shiju Rajan