Solved

Next and previous

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to go to page 12 93
New OSQA server has a ton of fake users 4 63
change time in cron 4 78
Soundcloud.com 4 25
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 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