Solved

Coldfusion Column Sorting

Posted on 2001-09-07
2
434 Views
Last Modified: 2013-12-20
I want to know how to sort the columns of a query.  I know how to do it via the SQL statement.  What I need is for a user to be able to pull up the webpage with query and click on the column headings of the table to sort it by that column(asc AND desc would be great...).  For example...  Lets say I have a table called "music", and I have fields: ID, Artist, Title, Description, and etc.  I want the user to be able to click on ID to sort the table by ID and if they click on Artist, sort by artist, and etc.  If there is anyone who can help me on this, it would be greatly appreciated.
0
Comment
Question by:bptacek
2 Comments
 
LVL 1

Accepted Solution

by:
snakehollywood earned 150 total points
ID: 6464528
Put buttons into your table headers that will act as the sort button.
When the button is clicked on, it will pass the name of the column to sort into a hidden form field, and then submit the form back to the same page.

e.g

<td><input type="submit" name="sortorder" value="Name" onclick="document.forms[0].orderby.value='name ASC'"></td>

this puts a button into your column header, which when clicke don, will pass the value "name ASC" into the hidden form field called orderby.

At the top of the page you simply check for the existance of the form button, if it exists then apply a dynamic where clause using the hidden formfield.

e.g

<cfquery>
select * from table
<cfif isdefined('form.sortorder')>
order by #form.orderby#
</cfif>
</cfquery>

this will order your query by the column "name" in ascending order.

Now you just create buttons for each column you wish to sort. You can use image buttons for ASC and DESC options.

0
 

Author Comment

by:bptacek
ID: 6464741
Thanks snakehollywood, that makes sense.  Thanks again!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now