Page 1 of 1

Need Help sorting...

Posted: Thu Oct 07, 2010 1:06 pm
by prototype18
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.

Code: Select all

<?
//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, 8);
                    $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++;
        }
    }
}

                

			}

Re: Need Help sorting...

Posted: Thu Oct 07, 2010 1:14 pm
by twinedev
Can you give an example listing of the files, and verify the code you posted above?

You have this line which makes me think your code didn't properly get pasted here:

Code: Select all

$codate = substr($file, 70, <img src="./images/smilies/icon_cool.gif" alt="8)" title="Cool" />;
But definitely an example the filenames you are talking about would help.

-Greg

Re: Need Help sorting...

Posted: Thu Oct 07, 2010 1:16 pm
by prototype18
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.

Re: Need Help sorting...

Posted: Fri Oct 08, 2010 9:02 am
by prototype18
:banghead:

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?

Re: Need Help sorting...

Posted: Fri Oct 08, 2010 9:24 am
by twinedev
I'd still need an example list of filenames you are working with to help more, so I don't have to guess at it.