Solved

Next and previous

Posted on 2000-03-17
4
191 Views
Last Modified: 2013-12-24
Hi there...

I have a cfm page which searches a database and then uses the query to display results using cfooutput into a number of text fields on the page.

What is the easiest way to provide a NEXT button which would display the next found record in the fields.

thanks for the help.
0
Comment
Question by:RICHARDH
4 Comments
 
LVL 37

Expert Comment

by:meverest
Comment Utility
It gioes something like this.  i do this from memory, so i apologise in advance if i do not have the tags right - ie, i can't remember if it is maxrows or rowcount or maxrecords or whatever, but the basic structure should be enough to give you the idea....

<cfset maxrows=10>

<cfif isdefined('form.startrow')>
  <cfset startrow=form.startrow>
<cfelse>
  <cfset startrow=1>
</cfif>

<cfquery name=list ... ... ...>
  [sql stuff]
</cfquery>

<cfif isdefined('form.next')>
  <cfset startrow = min(startrow+10, list.recordcount-10)>
</cfif>

<cfif isdefined('form.prev')>
  <cfset startrow=max(startrow-10, 1)>
</cfif>
<form action="thisform.cfm" method=post>

<cfoutput>Displaying records #startrow# - #startrow+10# of #list.recordcount#<p></cfoutput>

[table heading]
<cfoutput query=list startrow=#startrow# maxrows=#maxrows#>
  [table stuff]
</cfquery>
<cfif startrow gt 1><input type=submit name=prev value="PREV #maxrows#"></cfif>
<cfif startrow lt list.recordcount><input type=submit name=next value="NEXT #maxrows#"></cfif>
</form>



0
 

Expert Comment

by:mimilafleur
Comment Utility
hi Richard
you may find the answer at this address (hopefully)

http://www.cftutorials.com/index.cfm?mode=DisplayTutorial&TuUUID=CA3C99A0-EC34-11D3-85030050DABEAE1B

good luck

mimi
0
 
LVL 1

Expert Comment

by:rod_nolan
Comment Utility
Hi Richard,

I've also answered this one a few times in this group.  You can find the most recent one at http://www.experts-exchange.com/jsp/qShow.jsp?ta=coldfusion&qid=10310035

Generally, it's probably best to search through the previously answered questions list before you post a question. You might get your answer a bit quicker and it'll cost you less points. :)

Good Luck,
Rod
0
 

Accepted Solution

by:
lcj earned 50 total points
Comment Utility
Try the following code

You should replace "cfparam name" to your field variables.

<!-- Initialise constants -->
<cfset MaxRows = 10>
<!-- Initialise all fields if they do not exist -->
<cfparam name="start" default="1">
<cfparam name="us_id" default="">
<cfparam name="us_dp_code" default="">
<cfparam name="us_name" default="">
<cfparam name="us_address_line_1" default="">
<cfparam name="us_access" default="">


<!-- What is the next row to start at -->
<cfset PrevStart = Start - MaxRows>
<cfset Nextstart = start + MaxRows>

<!-- Previous Button Code -->
<cfif prevstart GTE 1>
<cfoutput>
<form action="usercreation.cfm" method="post">
<input type="hidden" name="start" value="#PrevStart#">
<input type="hidden" name="us_id" value="#US_ID#">
<input type="hidden" name="us_dp_code" value="#US_DP_CODE#">
<input type="hidden" name="us_name" value="#US_NAME#">
<input type="hidden" name="us_address_Line_1" value="#US_ADDRESS_LINE_1#">
<input type="hidden" name="us_access" value="#US_Access#">
<input type="submit" value="<< Previous #MaxRows# Records">
</form>
</cfoutput>
</cfif>
</td>
<td>
<form action="" method="post">
<input type="submit" value="Update User Record">
</form>
</td>
<td>
<form action="viewall.cfm" method="post">
<input type="submit" value="View All Records">
</form>
</td>
<td>
<!-- Next Button Code -->
<cfoutput>
<form action="usercreation.cfm" method="post">
<input type="hidden" name="start" value="#NextStart#">
<input type="hidden" name="us_id" value="#US_ID#">
<input type="hidden" name="us_dp_code" value="#US_DP_CODE#">
<input type="hidden" name="us_name" value="#US_NAME#">
<input type="hidden" name="us_address_Line_1" value="#US_ADDRESS_LINE_1#">
<input type="hidden" name="us_access" value="#US_Access#">
<input type="submit" value="Next #MaxRows# Records >> ">
</form>
</cfoutput>
</center>
</td>
</tr>
</table>
</body>
</html>
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now