prototype18 Posted October 7, 2010 Share Posted October 7, 2010 I have a situation where I need to sort files on a screen based on the date that is embedded into the file name. The problem is that I am sorting based off the file name, and when I get my output the LEGACY file always comes out on top of the sort because it starts with a 0 meanwhile the rest have dates appended the the filename so I don't have a problem sorting those. Please help me if you can. <?//Special case for extra files IF($Recordmyrow['App'] == "(Printable)") { $display = false; $column3 = "Printable VER"; IF($securityvalue == "P") { if(substr($path, 0, 5) == "file:") { $filename = substr($path, 5); if(file_exists($filename)) { $basename = substr($filename, 0, strrpos($filename, '.')); $ext = ".pdf"; $allfiles = glob("{$basename}*.pdf"); rsort($allfiles, SORT_NUMERIC); foreach($allfiles as $file) { if($ext == ".pdf") { $column4 = "<a href=\"pdf.php?src={$file}\">VIEW</a><br />\n"; $codate = substr($file, 70, ; $co = substr($file, 59, 1); if ($codate != "pdf") { $column3 = "Printable File - ".$codate; } elseif ($codate == "pdf") { $column3 = "Printable File - LEGACY"; } IF($lastGroup != $Recordmyrow['Grouping']) { $lastGroup = $Recordmyrow['Grouping']; ?> <TR> <TD colspan="4" align="center" bgcolor="#418765"><B><FONT color="white"><? echo $Recordmyrow['Grouping'] ?></FONT></B></TD> </TR> <? } ?> <TR> <TD class="display" align="center" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column1 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column2 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column3 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>" align="center"><B><? echo $column4 ?></B></TD> </TR> <? $rowcount++; } } } else { $column4 = "Not Available"; ?> <TR> <TD class="display" align="center" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column1 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column2 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>"><B><? echo $column3 ?></B></TD> <TD class="display" bgcolor="<?=changeColor($rowcount)?>" align="center"><B><? echo $column4 ?></B></TD> </TR> <? $rowcount++; } }} } Quote Link to comment https://forums.phpfreaks.com/topic/215359-need-help-sorting/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 7, 2010 Share Posted October 7, 2010 Need Help sorting... Yes, but you didn't state what you are trying to accomplish, nor did you show example data and the expected results vs the current results. Quote Link to comment https://forums.phpfreaks.com/topic/215359-need-help-sorting/#findComment-1119904 Share on other sites More sharing options...
prototype18 Posted October 7, 2010 Author Share Posted October 7, 2010 Output is... File (Printable) Printable - yyyymmdd VIEW File (Printable) Printable - LEGACY VIEW File (Printable) Printable - 20101020 VIEW File (Printable) Printable - 20100920 VIEW Legacy need to be on the bottom. $codate is just a substr function to grab the date embedded in the file name for display and sorting. Quote Link to comment https://forums.phpfreaks.com/topic/215359-need-help-sorting/#findComment-1119905 Share on other sites More sharing options...
prototype18 Posted October 8, 2010 Author Share Posted October 8, 2010 Is there a way I can make the LEGACY (or oringinal) file float to the bottom, while keeping the numerical values from the substr in a high to low order? Quote Link to comment https://forums.phpfreaks.com/topic/215359-need-help-sorting/#findComment-1120188 Share on other sites More sharing options...
litebearer Posted October 8, 2010 Share Posted October 8, 2010 just a thought (presuming the legacy or first file does NOT start with a number)... while looping thru the list of files, do an IF first character is a number list it else skip. then when looping is done, display the file that does NOT start with a number Quote Link to comment https://forums.phpfreaks.com/topic/215359-need-help-sorting/#findComment-1120246 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.