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
Solved

Coldfusion Column Sorting

Posted on 2001-09-07
2
446 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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Server specifications for web hosting 7 93
Google Crawl Errors Producing 404 Errors 4 84
JKS to store upstart data 2 106
Configure a Local PHP Interpreter for Phpstorm 2 345
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…
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 properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…

828 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