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

display query results in batches

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a guestbook written by a previous developer. It queries the database and displays all the entries! I want to modify it so it displays 10 or so at a time. I tried using hidden form fields to pass the current record number but it fails help on doing this any one?
 
If you can find a copy of "Cold Fusion - Fast & Easy Web Development" by T.C. Bradley III, it tells you exactly how to do that on pages 49-51. I'll try to describe the method briefly to give you the idea.

At the top of the page, define a variable FirstRow and give it a default of 1. Next, check to see if a URL variable, (e.g. URL.First) is defined, and if it is, set FirstRow = to URL.First. Then, define a variable StartNextPage = FirstRow + NumRowsToDisplay(Which is however many rows you want displayed at a time.). This will tell you what row to start the next screen on. When you are output you results, use FirstRow as StartRow, and define a link labeled "Next 10 Items" to the next page, passing URL.First which you give a value of StartNextPage. You can then navigate through the results. You'll have to add some additional logic for "Previous 10" and checking when you are at the end of your results, but hopefully, this is enough to get you started.

Sorry if I was too verbose, but I just happened to have done this very thing last week. Good luck! Let me know if you need anything else. :)
 
On second thought, here are are couple of snippets of code from my page that should help you.

Put this at the top of your page:

Code:
<cfparam name=&quot;FirstRow&quot; default=&quot;1&quot;>
<cfif IsDefined (&quot;URL.First&quot;)>
	<cfset FirstRow = URL.First>
</cfif>
<cfset StartNextPage = FirstRow + NumRowsToDisplay>
<cfset StartLastPage = FirstRow - NumRowsToDisplay>

And, put something like this at the bottom of your page after you display the results:
Code:
<cfset FirstRow = FirstRow + NumRowsToDisplay>
<cfoutput>
	<cfif #StartLastPage# GTE 1>
		<a href=&quot;QuestionFormPage.cfm?first=#StartLastPage#&quot;>Previous Question</a>
	</cfif>
	<cfif #StartNextPage# LTE #GetQuestions.RecordCount#>
		<a href=&quot;QuestionFormPage.cfm?first=#StartNextPage#&quot;>Next Question</a>
	</cfif>
</cfoutput>

Hope this helps! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top