[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

re-order table generated by coldfusion by clicking on header

Posted on 2003-03-27
5
Medium Priority
?
161 Views
Last Modified: 2013-12-24
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).
0
Comment
Question by:bobwils
5 Comments
 
LVL 8

Expert Comment

by:TallerMike
ID: 8220421
<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>
0
 
LVL 6

Expert Comment

by:dash420
ID: 8222584
above comments will solve your problem
0
 
LVL 17

Accepted Solution

by:
anandkp earned 200 total points
ID: 8222680
a small addition to the above suggestion

<cfparam name="orderBy" default="ID">
<cfparam name="AscDesc" default="Asc">

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

Then the links for the headers would do this:

<CFIF AscDesc EQ 'Asc'>
   <a href="alcuin.cfm?orderBy=year&AscDesc=Desc">Year in Desc order</a>
<CFELSE>
   <a href="alcuin.cfm?orderBy=year&AscDesc=Asc">Year in Asc Order</a>
</CFIF>

since u asked for both ascending & descending options !

K'Rgds
Anand
0
 

Author Comment

by:bobwils
ID: 8225669
Although the earlier comments worked, I wanted to do it in both ascending and descending order.  This answer worked wonderfully!  Thanks so much.
0
 
LVL 8

Expert Comment

by:TallerMike
ID: 8225693
Oops, I missed that part. Good catch Anand.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
Suggested Courses
Course of the Month8 days, 14 hours left to enroll

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question