Link to home
Start Free TrialLog in
Avatar of bobwils
bobwils

asked on

re-order table generated by coldfusion by clicking on header

I have a simple cfm page.  I am generating a table from a database and would like to be able to re-order the table according to the different headers in it.  The page is at http://saugus.byu.edu/gened/alcuin.cfm

Here is the code I am using to order the page now:
<cfquery name= "AlcuinQuery" datasource= "awards">
     SELECT * FROM AlcuinRecipient ORDER BY "ID" DESC
     </cfquery>

I would like to be able to let the user click on the header to sort either ascending or descending by year, name, position, or department.  I could do it fairly easily by creating different pages that linked to the header, but I would like to do it all in one page.

In other words, if you click on year then the page will be sorted by year (descending).  If you click on year again it will re-sort the page and make the years ascending.  If you click on name it will order the table according to name...etc.

Please let me know any suggestions you have (and if this makes sense).
Avatar of TallerMike
TallerMike

<cfparam name="url.orderBy" default="ID">

<cfquery name= "AlcuinQuery" datasource= "awards">
    SELECT *
    FROM AlcuinRecipient
    ORDER BY #url.orderBy# DESC
</cfquery>

Then the links for the headers would do this:

<a href="alcuin.cfm?orderBy=year">Year</a>
above comments will solve your problem
ASKER CERTIFIED SOLUTION
Avatar of anandkp
anandkp
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bobwils

ASKER

Although the earlier comments worked, I wanted to do it in both ascending and descending order.  This answer worked wonderfully!  Thanks so much.
Oops, I missed that part. Good catch Anand.