As you are generating HTML, you may want to consider a Javascript based solution. That way the server doesn't have to care and can defer the sorting to the client (and hence let the user decide what to sort for).
There even is an
example of how to do that on the W3C web page, with clickable headers and shit.
holli
You can lead your users to water, but alas, you cannot drown them.