Link to home
Start Free TrialLog in
Avatar of diecasthft
diecasthft

asked on

Next/Previous record in Coldfusion

I have an issue with my next record code in Coldfusion. I have a database with electronics information in it at several installations...so installation 1 might have 10 pieces of electronics. I distinguish the different pieces by what building they're located in. So I have a page that allows me to search by installation, and then it returns a list of all of the electronics at that installation. I have an edit link where I can open a specific record and I pass the installation name and ther building number thru the url. My problem is that I want to have a next/previous button at the top of the edit page that opens when I select the edit button. If I select the edit button on a building number in the middle of the installation list, it automatically opens the first record of the query, not the record I selected in the list. If I add a where clause in my query to include the building number, then I get the right record, but then only one record shows up and therefore there is no next/previous button to get to the next record in the query. Can I use the next/previous while still starting in the middle of a recordset?? Below is my code....any help would be greatly appreciated...I've been fighting this for some time now......

editDSN -----------------------

<CFSET EditMode=IsDefined("URL.INSTALLATION_NAME")>
<CFSET EditMode=IsDefined("URL.BUILDING")>

<CFIF EditMode>

<cfset SESSION.urlpass.INSTALLATION_NAME = URL.INSTALLATION_NAME>
<cfset SESSION.urlpass.BUILDING = URL.BUILDING>

<CFSET ORGANIZATION=Trim(DSNedit.ORGANIZATION)>
    <CFSET STREET_ADDRESS=Trim(DSNedit.STREET_ADDRESS)>
      <CFSET BLDGNO=Trim(DSNedit.BLDGNO)>
      <CFSET CITY=Trim(DSNedit.CITY)>
      <CFSET STATE=Trim(DSNedit.STATE)>
      <CFSET ZIP_CODE=Trim(DSNedit.ZIP_CODE)>
      <CFSET RCIO_REGION=Trim(DSNedit.RCIO_REGION)>

<CFSET FormTitle="Update Installation">
    <CFSET ButtonText="Update">
   
<CFELSE>

<CFSET ORGANIZATION="">
    <CFSET STREET_ADDRESS="">
      <CFSET BLDGNO="">
      <CFSET CITY="">
      <CFSET STATE="">
      <CFSET ZIP_CODE="">
      <CFSET RCIO_REGION="">

<CFSET FormTitle="Add an Installation">
    <CFSET ButtonText="Insert">

</CFIF>

<cfquery name="IDDB" datasource="DSNSwitch_PM">
SELECT DISTINCT ORGANIZATION
FROM DSNSWITCH_PM.POC_INFORMATION
</cfquery>

<cfquery name="Addr1" datasource="DSNSwitch_PM">
SELECT DISTINCT STREET_ADDRESS
FROM DSNSWITCH_PM.POC_INFORMATION
</cfquery>

<cfquery name="Cityfield" datasource="DSNSwitch_PM">
SELECT DISTINCT CITY
FROM DSNSWITCH_PM.POC_INFORMATION
</cfquery>

<cfquery name="Statefield" datasource="DSNSwitch_PM">
SELECT DISTINCT STATE
FROM DSNSWITCH_PM.POC_INFORMATION
</cfquery>

<cfquery name="Zipfield" datasource="DSNSwitch_PM">
SELECT DISTINCT ZIP_CODE
FROM DSNSWITCH_PM.POC_INFORMATION
</cfquery>

<cfquery name="Regionfield" datasource="DSNSwitch_PM">
SELECT DISTINCT RCIO_REGION
FROM DSNSWITCH_PM.POC_INFORMATION
</cfquery>


<CFQUERY DATASOURCE="DSNSwitch_PM" NAME="GetCount">
SELECT *
FROM DSNSWITCH_PM.POC_INFORMATION
WHERE POC_INFORMATION.ORGANIZATION='#URL.INSTALLATION_NAME#'
AND POC_INFORMATION.BLDGNO='#URL.BUILDING#'
</CFQUERY>
      
<CFSET recordperpage = 1>

<CFPARAM NAME="URL.startrow" default="1" type="numeric">
<CFSET totalRows = GetCount.recordCount>

<CFSET endRow = min(URL.startrow + recordperpage -1, totalRows)>

<CFSET startRowNext = endRow + 1>

<CFSET startRowBack = URL.startRow - recordperpage>

<html>
<head>
<title>Untitled Document</title>

<body>
<cfform name="InstallationForm" action="LMRUpdate.cfm" method="post">

<table width="800"><td>
<h3><span class="style1 style7">Information for</span> <CFOUTPUT><span class="style1 style2">#ORGANIZATION#</span>;<BR>
</CFOUTPUT></td>
<tr><td><cfoutput>
<span class="style10">Displaying</span> <span class="style7 style1 style8"><strong>#URL.startRow#</strong></span>
<span class="style10 style7">of</span> <span class="style7 style1"><strong><span class="style2">#totalRows#</span></strong></span> <span class="style10">Record(s)</span>
</cfoutput>

<cfinclude template="NextNIncludeBackNext1.cfm"></td></tr>
</table>      
<cfloop query="GetCount" startRow="#startRow#" endRow="#endRow#">      

---- BUNCH OF FORM FIELDS HERE -----

</cfloop>
</body>
</CFFORM>
</html>

Then my nextininclude template --------------------

<cfset SESSION.urlpass.INSTALLATION_NAME = URL.INSTALLATION_NAME>
<cfset SESSION.urlpass.BUILDING = URL.BUILDING>

<cfoutput>
<cfif startRowBack gt 0>
<a href="#CGI.script_name#?ARMY_INSTALLATION_NAME=#SESSION.urlpass.INSTALLATION_NAME#&BUILDING=#SESSION.urlpass.BUILDING#&startRow=#startRowBack#">
<img src="../../Images/BrowseBack.gif" width="40" height="16" alt="Previous Record" border="0" /></a>
</cfif>

<cfif startRowNext lte totalRows>
<a href="#CGI.script_name#?ARMY_INSTALLATION_NAME=#SESSION.urlpass.INSTALLATION_NAME#&BUILDING=#SESSION.urlpass.BUILDING#&startRow=#startRowNext#">
<img src="../../Images/BrowseNext.gif" width="40" height="16" alt="Next Record" border="0" /></a>
</cfif>

</cfoutput>
ASKER CERTIFIED SOLUTION
Avatar of stu215
stu215
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial