This is a simple function I wrote that comes in handy when I want to have href links on a page to sort a SQL query (in both ascending and decending orders, the two will alternate). I will make this into an object later on, but it works great as a function too.
The function relies on these values:
$order_title - What to label the link, passed to function.
$order_table - What row to sort by for that link, passed to function.
$sortorder - Created by the function in the href links, the function gets this value as a global var.
$order_options - The function makes this global var containing the SQL code which you put into the query.
$order_number - Global var, used to generate the sequencial link numbers.
$extra - Any extra variables that you want put in the href link (could be anything).