if($_GET['sort'] == 'asc'){
echo "<img src='รูปลูกศรหัวขึ้น' onclick='location.href='test.php?sort=asc'>";
$sql = "select * from tb_name where 1=1 order by id asc";
}else{
echo "<img src='รูปลูกศรหัวลง' onclick='location.href='test.php?sort=desc'>";
$sql = "select * from tb_name where 1=1 order by id desc";
}
$query = mysql_query($sql);
while($ft = mysql_fetch_assoc($query)){
// do some thing
}