Somebody recommended me to ask it at NoggDog … but of course any good solution of somebody else is fine
I’m making a directory listing of an homepage with 3 columns : file name – time – size
Now I want to make the columns sortable – ascending AND descending – in PHP (NOT javascript!!)
But I don’t get it to work (only one way works)
But I want it to work from ASC to DESC and visa versa.
Can you help me out please and make changes to the code below so it works (td header click asc and td header click desc for all three columns )??
Code so far
[code=php]<?php
error_reporting(0);
@ini_set(‘display_errors’, 0);
$dir = “*”;
$read_dir = glob($dir);
function sort_name($a,$b) {
return glob($a) < glob($b);
}
function sort_size($a,$b) {
return filesize($a) < filesize($b);
}
function sort_time($a,$b) {
return filemtime($a) < filemtime($b);
}
if($_GET[‘sort’]==’size’) {
usort($read_dir, “sort_size”);
}
elseif($_GET[‘sort’]==’time’) {
usort($read_dir, “sort_time”);
}
else {
sort($read_dir, “sort_name”);
}
echo “<table border=’1′>”;
echo “<tr>”;
echo “<td><a href=?sort=name>Name</a></td>”;
echo “<td><a href=?sort=size>Size</a></td>”;
echo “<td><a href=?sort=time>Time</a></td>”;
echo “</tr>”;
foreach ($read_dir as $files) {
echo “<tr>”;
echo “<td style=’width:300px;’>” . $files . “</td>”;
echo “<td style=’width:170px;text-align:center;’>” . date(“d.m.Y H:i:s”, filemtime($files)) . “</td>”;
echo “<td style=’width:80px;text-align:right;’>” .filesize($files) . ” B</td>”;
echo “</tr>”;
}
echo “</table>”;
?>
Kind regards