#1: JavaScript. Otherwise you have to resort to reloading the page to recalculate the total.
#2: Think about the problem at hand. You need to change the sort order, which can be easily done with your SQL query. You'll probably want to think about a link that a user can click on which re-runs the SQL that displays the page, but this time, figure out which header the user clicked on (by specifying something unique about the header in the URL the user clicked on) as well as the desired sort order (its either ascending or descending so you can toggle this on/off, true/false, 0/1, asc/desc, etc).