Sorting problem with most recent uploaded file
Posted: Sat Jan 16, 2010 1:47 pm
Hi,
I'm using the following code to show a list of files. The files should be sorted by the most recent date.
This was working correctly in 2009, but since this year, there's a problem with sorting. The previous upload is from September 2009, and this is the first item on the page. In January 2010, there where some new files uploaded, and they are shown at the bottom of the page, just above January 2009.
Could someone help me how to modify the code to sort by year and then month, so that January 2010 shows on top of the page?
I'm using the following code to show a list of files. The files should be sorted by the most recent date.
Code: Select all
<?php
$recent = $site_class->data_get(db_productfiles,'','','pfile_date_created DESC','500');
$n=1;
$pout = array();
$monthlist = array ('01' => 'January', '02' => 'February', '03' => 'March', '04' => 'April', '05' => 'May', '06' => 'June', '07' => 'July', '08' => 'August', '09' => 'September', '10' => 'October', '11' => 'November', '12' => 'December');
while (list($name, $value) = each($recent)) {
//foreach ($recent as $name => $value){
$time = $recent[$name]['pfile_date_created'];
list ($year,$month) = explode("-",$time);
$time = $month."-".$year;
if (empty($pout[$time])){
$pout[$time] = "<strong>".$monthlist[$month]."-".$year."</strong><br />";
}
$pout[$time] = $pout[$time]."<a href=\"PDF/Test_PDF/".$recent[$name]['pfile_file']."\"class=\"a\">".$recent[$name]['pfile_description']."</a> - ".$recent[$name]['pfile_type']." - ".$recent[$name]['pfile_size']."Kb<br />";
$n++;
}
krsort($pout);
foreach ($pout as $name => $value){
echo ucfirst($value)."<br />";
}
}
?>Could someone help me how to modify the code to sort by year and then month, so that January 2010 shows on top of the page?