You can do this server side by making links that define calls which call back to your script with a parameter telling the sort key and perhaps a direction. You'd then use that sort key to sort the table into a temporary AoA which you'd use to output your table.

Another alternative which you might want to look into (if it's acceptable to use Javascript) is any of the umpteen bazillion JS live table packages (see for example Yahoo's YUI). These have the advantage of sending the page one time and then the sorting takes place client side rather than requiring a server round trip. You could also use JQuery to whip up your own if you need fancier behavior that an off the shelf solution doesn't provide.

An unrelated note: don't prefix subroutine calls with an &; it has a special meaning which while you're probably not going to get into trouble here could cause headaches down the road if you get into a bad habit.

The cake is a lie.
The cake is a lie.
The cake is a lie.


In reply to Re: Sorting a table by Fletch
in thread Sorting a table by pc0019

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.