kensington43
Technical User
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:
The two fields attempt that wont work:
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>