Solved

Coldfusion Column Sorting

Posted on 2001-09-07
2
460 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

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…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

688 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