for event "onlick" for every header of column in table with results create function, that will call the same .php file passing it variable
,that value will depend on header you click, for example, when you click header of table's column where column contains data of field "name", your onlick function will call .php?
sortby="name"
for example:
javascript:
function ClickHeader(id_column)
{
switch (id_column) {
case "name":
document.location="yourphpfile.php?sortby='name'";
case "..":
.......
}
}
in your *.php file you will form SELECT statement according the value of "sortby" variable:
for example:
switch ($sortby)
{
case "name":
$SQLsort=" order by name";
break;
default:
$SQLsort=" order by id";
}
and then yuor SELECT statement:
$Select="Selet * from mytable ".$SQLsort;