Below iv tried to make a function wich sorts the date, but
I cant get that to work either. Iv also changed the date output so it only shows the year, thinking this would make sorting easier. Sorry for nagging, but does anybody have any ideas ?
The idea is to get the script to sort after date, with the newest songs first.
<?php
function sort_music($a,$b) {
return $a['date'] > $b['date'];
}
$myFiles=array();
$homedir = "music/cd/normal";
$dir = opendir("$homedir");
while(FALSE !== ($file = readdir($dir))) {
if($file=="." || $file==".."||$file=="index.php"||$file=="music.php"||ereg("index|html|doc|instrumental|normal",$file)) {
} else {
$myFiles[] = "$file";
}
}
closedir($dir);
usort($myFiles,'sort_music');
echo "<table>";
echo "<tr><td colspan=4><b>Christian</b></td></tr>";
$heading = array("Nr","Song","Size","Date (Created)");
echo "<tr>";
foreach($heading as $head_value) {
echo "<td class=nav2>$head_value</td>";
}
echo "</tr>";
foreach($myFiles as $value) {
$sjekk_size = stat("music/cd/normal/$value");
$size = $sjekk_size['size'];
$sjekk_date = stat("music/cd/normal/$value");
$datec = $sjekk_date['mtime'];
$counter_cd2++;
$del = split("-",$value);
echo "<tr>
<td class=nav1>$counter_cd2</td>
<td class=nav1><a class=cd href=music/cd/normal/$del[0]>" . substr($del[0],0,-4) . "</a></td>
<td class=nav1>" . substr("$size",0,-6) . "," . substr("$size",1,-5) . " MB</td>
<td class=nav1>" . date("Y",$datec) . "</td>
</tr>";
}
echo "</table>";
?>