mixing next n records with cfswitch order by problem
Hello;
I'm trying to make 2 types of page navigation work together. both work fine independently, but when I put my next n record code together with my change order by code, when you hit the next button, it goes back to the set default for the order by. I know I need to change some code logic in my scripts that run the next n records, but I'm not sure what I need to change in it to make it all work together properly. I am attaching the code, in it's rawest form, but all code is here for both features.
<cfparam name="sort" default="1">
<cfquery name="getMerch" datasource="#APPLICATION.dataSource#">
SELECT merchID, MerchName, MerchDescription, MerchPrice, MYFile, CategoryID
FROM Merchandise
WHERE CategoryID = 2
ORDER BY
<cfswitch expression="#sort#">
<cfcase value="1">MerchName</cfcase>
<cfcase value="2">MerchPrice</cfcase>
</cfswitch>
</cfquery>
<cfset rowsPerPage = 3>
<cfparam name="URL.startRow" default="1" type="numeric">
<cfset totalRows = getMerch.recordCount>
<cfset endRow = min(URL.startRow + rowsPerPage - 1, totalRows)>
<cfset startRowNext = endRow + 1>
<cfset startRowBack = URL.startRow - rowsPerPage>
<cfoutput>
<!--- changes the order by --->
<cfif sort is 1>
<a href="#CGI.script_name#?sort=#IIF(sort is 1, '2', '1')#" class="pre2Nav">Order By Price</a>
<cfelse>
<a href="#CGI.script_name#?sort=#IIF(sort is 2, '1', '2')#" class="pre2Nav">Order By Product</a>
</cfif>
<!--- my next n buttons --->
<cfif startRowBack GT 0>
<a href="#CGI.script_name#?startRow=#startRowBack#" class="pre2Nav">< Back</a>
</cfif>
<cfif startRowNext lte totalRows>
<a href="#CGI.script_name#?startRow=#startRowNext#" class="pre2Nav">More ></a>
</cfif>
</cfoutput>
<cfloop query="getMerch" startRow="#URL.startRow#" endRow="#endRow#">
<cfoutput>
All my output goes here
</cfoutput></cfloop>
Can anyone help me get this to work together? is it possible? and more importantly, how hard is it going to be to do this?
Thank you.
