Sorting tables

Voo

Voo

Associate
Joined
6 Jul 2006
Posts
113
Location
Hull, East Yorks
I have a few tables on a website that are creating by querying a mySQL database to output the data.

I need to be able to order one of the columns in Descending order from highest to lowest number.

Any one got any good guides or snippets of code to help me out with this?
I'm assuming it would be some kind of javascript.
 
The easiest way would be to get the query to sort the data for you. I'm a DB2 expert rather than mySQL but I assume that it will support an ORDER BY clause on the query so you end up with something like:

Code:
select col1, col2, col3
from table
order by col1 desc
 
This is what i was looking for:

http://kryogenix.org/code/browser/sorttable/

While this does the required effect, i want to be able to automatically sort the tables on one specific column only, not all columns. This is so that the end user doesn't have to press the title to get it in order. I want it to automatically appear in order as soon as the page loads.

Any ideas?
 
Last edited:
I can't believe someone went to the effort of writing that javascript! Fair play to them, though. But still :eek:

I'd just make a <a> tag with ?order=colName&sort=desc and then inject that into the sql query.
But if the JS is good enough, then so be it :)
 
Probably best to use both. We are using something similar through one of the controls created by telerik. Set a default order in the SQL and then allow the user to perform and other sorts that they wish on the client side uising JavaScript. Gives the users a lot more control on viewing the information, and without the need for trips back to the server.
 
Back
Top Bottom