Need Help sorting...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
prototype18
Forum Commoner
Posts: 25
Joined: Wed Aug 18, 2010 9:52 am

Need Help sorting...

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

                

			}
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Need Help sorting...

Post 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
prototype18
Forum Commoner
Posts: 25
Joined: Wed Aug 18, 2010 9:52 am

Re: Need Help sorting...

Post 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.
prototype18
Forum Commoner
Posts: 25
Joined: Wed Aug 18, 2010 9:52 am

Re: Need Help sorting...

Post 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?
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Need Help sorting...

Post 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.
Post Reply