Solved

Next and previous

Posted on 2000-03-17
4
227 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
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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
website does not load without www 12 74
Website being blocked? 3 129
Setting Up Local Lan Web Server 1 65
Domino Website - Redirection 12 84
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…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 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