• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

mixing next n records with cfswitch order by problem

Community Beginner ,
Mar 22, 2010 Mar 22, 2010

Copy link to clipboard

Copied

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.

TOPICS
Advanced techniques

Views

868

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 22, 2010 Mar 22, 2010

Copy link to clipboard

Copied

What is the value of sort when you look for the next n records?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 22, 2010 Mar 22, 2010

Copy link to clipboard

Copied

the value is changed to 2 if you click the link, that's when next n record fail. when it's set to the default, which is 1, it's fine.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 22, 2010 Mar 22, 2010

Copy link to clipboard

Copied

The problem is either that the variable is not what you expect, or that your switch case code is wrong.  Try this

<cfdump var = "isDefined('sort')>

<br>

<cfparam name="sort" default="1">

<cfdump var = "sort is  #sort#">

<br>

<cfswitch expression="#sort#">
<cfcase value="1">MerchName</cfcase>
<cfcase value="2">MerchPrice</cfcase>
</cfswitch>

Do you get the expected results?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 22, 2010 Mar 22, 2010

Copy link to clipboard

Copied

It works fine, I get the proper results, accept when I hit next, then it goes back to the default #sort# that is 1 for the next set of records.

I believe the next n code needs to have stipulations in it for the #sort# setting, but I'm not sure how to approach that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 22, 2010 Mar 22, 2010

Copy link to clipboard

Copied

What did this give you when you hit next?

<cfdump var = "isDefined('sort')>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 22, 2010 Mar 22, 2010

Copy link to clipboard

Copied

if I use this:

<cfdump var = "#isDefined('sort')#">

I get YES as the output, even when I hit the next button and change the category.

If I use this:

<cfdump var = "isDefined('sort')>

all I get is this:

isDefined('sort')

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 22, 2010 Mar 22, 2010

Copy link to clipboard

Copied

Ok, I forgot the octothorps.  Try this:

<cfif isDefined('sort') is true>

<cfdump var = "sort is  #sort#">

<cfelse>

no variable named sort

</cfif>

<br>

<cfparam name="sort" default="1">

<cfdump var = "sort is  #sort#">

Then press next.  The objective is to see what is being passed and whether or not it's changing.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 22, 2010 Mar 22, 2010

Copy link to clipboard

Copied

when I put this code in I get this:

when it loads the page I get: sort is  1
I click on changing the order I get: sort is  2

when I click on next and it's set on sort is 2 It goes back to: sort is  1

does this help?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 23, 2010 Mar 23, 2010

Copy link to clipboard

Copied

Your original post does not show anything that would pass a variable named sort when you click next. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 23, 2010 Mar 23, 2010

Copy link to clipboard

Copied

that's what I'm asking for help with, I'm not sure how to make the links know the difference between the

2. Obviously it's going to use an if statement for 2 different links, but what would the code be in the link to realize it's been sorted differently?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 23, 2010 Mar 23, 2010

Copy link to clipboard

Copied

LATEST

after doing all this dumping looking for the variable.. can you help me figure out what to put in a link to

make this work?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation