This tutorial will demonstrate how to incorporate a navigation system the displays next X records per page. Not sure what I mean? Take a look at the same below:
This example will demonstrate how to incorporate it into your query results. The first thing we must do is define two variables:
The first variable we're defining by default is "Start". We're giving this a value of 1. The variable "start" will be used to let the ColdFusion server know which record we will want to begin at to display on the current page. The next variable is "disp", this variable will let ColdFUsion server know how many records to display per page. You can make this value any number you want.
<!--- Start displaying with record 1 if not specified via url --->
<CFPARAM name="start" default="1" />
<!--- Number of records to display on a page --->
<CFPARAM name="disp" default="5" />
The variable displayed above will make the magic appear, next let's query the database for all records:
<!--- Fetch records --->
<CFQUERY name="data" datasource="MyDB" />
SELECT MyField
FROM MyDB
ORDER BY MyField
</CFQUERY>
Ok, now that you have your database queried and you've defined where to start and how many rows to display, we're ready to begin displaying the data on the page:
Platforms Tested: CF5 Total Views: 74,825 Submission Date: September 17, 2002 Last Update Date: August 25, 2011 All Tutorials By This Autor: 47
Discuss This Tutorial
Hi, This script is good and I customized as per my requirments. Only problem is that I have used this on search page and if query returns lets say 500 records, first page shows 5 recs and when I do next the query is executed again showing some more recs. I want to somehow make the query run after the 5th rec only and dont have the query return all 500 records everytime I move from one page to the next... should be a way to do this.. I am thinking of cache right now... Do you have any suggestions...
This one is a must have script and I rate 5 starts for it.
Posted on 10/12/2006
I just wanted to express my gratitude for your most helpful script. I have been looking for and writing a script to perform this exact action. This script is very easy compared to how I was approaching the task. You are the bomb Pablo...THANK YOU!!
Posted on 05/19/2006
Another useful thing is to store the current location within the recordset in a session variable. This way you can always return to the same position from another page, say after editing a record.
Posted on 04/08/2006
Pablo,
I love the script and it works great for my usual stuff, but I've got a query that uses "group" and this code keeps going through every possible combination of records. Is there a way to show the records using this code even though I'm using the "group" tag?
D
Posted on 09/26/2005
This is a great little piece of coding.
Not complicated and it works.
Posted on 01/06/2005
Tony,
All you would likely have to do is manually append your URL variables to the anchor tags (example: Next
#next# records.)
If you like I have a custom tag (CF_Search_NextPrevious) that does Next/Previous links as well as page numbers. There is an attribute called "ExtraURLString" which allows you to add your own custom URL variables to be appended to the URL string. You can find it at http://www.jeffcoughlin.com/ or on the Macromedia ColdFusion Exchange.
Posted on 10/06/2004
I have worked though this tutorial and tried a few other, that all work well, but… I am passing some parameters to the results page. When I use the next button I loose these parameters. How do I keep the parameters in the link i.e. a form value so that it does get all the content from the database???
You can see what I mean if visit my test site at http://www.improvon.co.za/main.cfm use the property search at the top and you will see how the results page changes.