Solved

Next and previous

Posted on 2000-03-17
4
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 37

Expert Comment

by:meverest
ID: 2630081
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
ID: 2630158
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
ID: 2631545
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
ID: 2707166
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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

630 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