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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change the SQL ORDER BY ASC OR DESC clause via a form button

Status
Not open for further replies.

manj

Programmer
Sep 22, 2000
28
0
0
GB
This it possible using a form button to change the ORDER BY clause sequence from ascending to descending of a particular table column. Pressing the button again will do the reverse.

I have managed to order by a particular column but not reverse the order.

SQL STATEMENT...

<CFIF StructKeyExists(form,&quot;time_of_event&quot;)>
ORDER BY TimeOfEvent;
</CFIF>

<CFIF StructKeyExists(form,&quot;booking_name&quot;)>
ORDER BY BookingName;
</CFIF>

...

Any help will be great.
 
Try something like the following:
Code:
<cfparam name=&quot;URL.OrderClause&quot; default=&quot;Ascending&quot;>

<cfquery Name=&quot;EmployeeSearch&quot; datasource=&quot;cftrain&quot;>
select
e.salary
from employees e
<cfif URL.OrderClause eq &quot;Ascending&quot;>
   order by salary
<cfelse>
   order by salary desc
</cfif>
</cfquery>

<cfloop query=&quot;EmployeeSearch&quot; >
   <cfoutput>#salary#</cfoutput>
   <br>
</cfloop>

<form name=&quot;Test&quot; action=&quot;<current page>&quot;>
<cfif OrderClause eq &quot;Ascending&quot;>
   <input type=submit name=OrderClause Value=&quot;Descending&quot;>
<cfelse>
   <input type=submit name=OrderClause Value=&quot;Ascending&quot;>
</cfif>
</form>
 
Once upon a time, a very distant time of the past, there happened a thread:

thread232-194717

:) 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