>> I want to be able to click on a column header and toggle between ascending and descending sort; how do I go about doing this?
Load each record into a two dimensional associative array. For example, let's suppose you get four columns for each record from your HTML: name, age, town, job.
$row[0]['name'], $row[0]['age'], $row[0]['town'], $row[0]['job'] is one record.
$row[1]['name'], $row[1]['age'], $row[1]['town'], $row[1]['job'] is the second record. Etc.
To sort, you would use array_multisort:
http://us2.php.net/manual/en/function.array-multisort.php
>> Finally, I like to do pagination too and how do I go about this as well?
Pagination is simple. You set the number of records you want per page, get the page number from a GET variable, then move to the proper part of the array.
$pagesize = 10; // ten records per page
$page = $_GET['p']';
$start = ($page - 1) * $pagesize;
$size = count($row);
$totalpages = ceil($size / $pagesize);
for($i = $start; $i <= $size; $i++) {
echo "$row[$i][name] $row[$i][age] $row[$i][town] $row[$i][job]
\n";
}
for($i = 1; $i <= $totalpages; $i++) {
echo "
$i ";
}