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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.