Jump to content

Need Help sorting...


prototype18

Recommended Posts

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++;        }    }}                		}

 

Link to comment
https://forums.phpfreaks.com/topic/215359-need-help-sorting/
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/215359-need-help-sorting/#findComment-1119905
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/215359-need-help-sorting/#findComment-1120246
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.