Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting issue

Status
Not open for further replies.

kensington43

Technical User
Nov 29, 2005
50
US
The below sort works with just one field (names) but wont work when I put in another field (city) to sort on.

The one field attempt that works:
Code:
<!--- default value for sorting variable --->
<cfparam name="url.sort" default="#encrypt("names ASC","names")#">

<!--- query to sort, 'order by' used url variable to determine sort order --->
<cfquery name="get_data" datasource="#dsn#">
     SELECT *
     FROM cfml_example_data
     ORDER BY #decrypt(urldecode(url.sort),"names")#

</cfquery>

<table width="300" cellpadding="3" cellspacing="1">
<tr>
<td>
Names
<cfoutput>
<a href="index.cfm?sort=#urlencodedformat(encrypt("names DESC","names"))#"><</a> 
<a href="index.cfm?sort=#urlencodedformat(encrypt("names ASC","names"))#">></a> 
</cfoutput>
</td>

     </tr>
     <!--- output of data --->
     <cfoutput query="get_data">
          <tr>
               <td>
                    #names#
               </td> 
             
          </tr>
     </cfoutput>
</table>

The two fields attempt that wont work:
Code:
<!--- default value for sorting variable --->
<cfparam name="url.sort" default="#encrypt("names ASC","names")#">
<cfparam name="url.sort" default="#encrypt("city ASC","city")#">

<!--- query to sort, 'order by' used url variable to determine sort order --->
<cfquery name="get_data" datasource="#dsn#">
     SELECT *
     FROM cfml_example_data
<cfif isDefined("url.names")>
     ORDER BY #decrypt(urldecode(url.sort),"names")#
</cfif>
<cfif isDefined("url.city")>
     ORDER BY #decrypt(urldecode(url.sort),"city")#
</cfif>
</cfquery>

<table width="300" cellpadding="3" cellspacing="1">
<tr>
<td>
Names
<cfoutput>
<!--- links to sort data with --->
<a href="index.cfm?sort=#urlencodedformat(encrypt("names DESC","names"))#"><</a> 
<a href="index.cfm?sort=#urlencodedformat(encrypt("names ASC","names"))#">></a> 
</cfoutput>
</td>
<td>
City
<cfoutput>
<a href="index.cfm?sort=#urlencodedformat(encrypt("city DESC","city"))#"><</a> 
<a href="index.cfm?sort=#urlencodedformat(encrypt("city ASC","city"))#">></a> 
</cfoutput>
</td>
     </tr>
     <!--- output of data --->
     <cfoutput query="get_data">
          <tr>
               <td>
                    #names#
               </td> 
               <td>
                    #city#
               </td>         
          </tr>
     </cfoutput>
</table>
 
New Param Statement.

Code:
<cfparam name="url.sort" default="#encrypt("names ASC, city ASC","QuerySort")#">

New Order By Clause

Code:
ORDER BY #decrypt(urldecode(url.sort),"QuerySort")#

You should know that there is some issues with sending encrypted strings in urls... It can be a mess, and sometimes undecryptable.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Thanks I tried it without encryption but it kept giving me errors about parameters not being correct:

Code:
<!--- default value for sorting variable --->
<cfparam name="url.sort" default="names ASC, city ASC","QuerySort")">

<!--- query to sort, 'order by' used url variable to determine sort order --->
<cfquery name="get_data" datasource="#dsn#">
     SELECT *
     FROM cfml_example_data
     ORDER BY url.sort,QuerySort)
</cfquery>

<table width="300" cellpadding="3" cellspacing="1">
<tr>
<td>
Names
<cfoutput>
<!--- links to sort data with --->
<a href="index.cfm?sort=names DESC,names"><</a> 
<a href="index.cfm?sort=names ASC,names">></a> 
</cfoutput>
</td>
<td>
City
<cfoutput>
<a href="index.cfm?sort=city DESC,city"><</a> 
<a href="index.cfm?sort=city ASC,city">></a> 
</cfoutput>
</td>
     </tr>
     <!--- output of data --->
     <cfoutput query="get_data">
          <tr>
               <td>
                    #names#
               </td> 
               <td>
                    #city#
               </td>         
          </tr>
     </cfoutput>
</table>
 
Drop [red],"QuerySort")[/red] from your cfparam tag.

Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
Beat me to it ECAR. Been a while.

Have a good night.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top