You should cfqueryparam all your parameters and if you're passing DESC and
ASC in the URL you might want to look at those before using them in your SQL
too.

Adrian
Building a database of ColdFusion errors at http://cferror.org/

-----Original Message-----
From: Eric Nicholas Sweeney
Sent: 28 October 2008 17:46
To: cf-newbie
Subject: RE: Numerical order of query results


In regards to your sorting... Here's what I do:

When I need to sort a query - I will often pass the sort back to the page in
the URL...

                                                <cfif IsDefined("URL.SORT")>
                                                        ORDER BY #URL.SORT#
#URL.Order#
                                                <cfelse>
                                                        ORDER BY LastName
ASC
                                                </cfif>

That way I can place links in the Column heads and pass it back to the
query... Helps with sorting ASC and DESC in cases where Alpha/Numerical
sorting may be confusing/not obvious to the user - as it allows them to sort
they data as the wish.

A complete example would look like: (Which also allows the user to search on
the results as well.)

<cfquery name="qryGetEmailSubscribers" datasource="#Application.DSN#"
username="#Application.username#" password="#Application.password#">
SELECT EmailSubscribers.*
FROM EmailSubscribers
                <cfif IsDefined("Form.data")>
                WHERE #FORM.type# Like <cfqueryparam
cfsqltype="cf_sql_varchar" value="%#form.data#%">
                <cfelse>
                                <cfif IsDefined("URL.Term") AND #URL.Term#
NEQ "">
                                        WHERE LastName Like "#URL.Term#%"
                                                <cfif IsDefined("URL.SORT")>
                                                        ORDER BY #URL.SORT#
#URL.Order#
                                                <cfelse>
                                                        ORDER BY LastName
ASC
                                                </cfif>
                                <cfelse>
                                                <cfif IsDefined("URL.SORT")>
                                                        ORDER BY #URL.SORT#
#URL.Order#
                                                <cfelse>
                                                        ORDER BY LastName
ASC
                                                </cfif>
                                </cfif>
                </cfif>
</cfquery>

Maybe not the most elegant (?) - but it works.

- Nick


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-newbie/message.cfm/messageid:4100
Subscription: http://www.houseoffusion.com/groups/cf-newbie/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15

Reply via email to