in your sql query add another parameter ( $sort_by_column ) whose value will get change as per the user's click.
e.g.
if your query is ....
$sql = " SELECT field_name1, field_name2 FROM table_name"
then modify it as ........
$sql = " SELECT field_name1, field_name2 FROM table_name ORDER BY $sort_by_column"
whatever column you want to sort, you just need to pass the querystring as the column name
hope this helps
vishwa vivek garg
( http://vishwavivek.wordpress.com/)