Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting a file listing help... 1

Status
Not open for further replies.

admoore

IS-IT--Management
Joined
May 17, 2002
Messages
224
Location
US
I display the results of a directory listing of available pdf reports like this:

Code:
// List bbcm
$current_dir = "/public_html/reports/bbcm/";
$path = "reports/bbcm/";
$dir = opendir($current_dir);

echo (&quot;<br><hr width=225 align=left>Brown Mesa<br>&quot;);
while ($file = readdir($dir))

{
if ($file!=&quot;.&quot; && $file != &quot;..&quot;)
{

echo (&quot;<a href=\&quot;$path$file\&quot; target=\&quot;reports\&quot;>$file</a><br>&quot;);
}}


I need to sort the results alphabetically.... Can anyone help here, I guess I need to 1st write to an array, then sort array? Any help is greatly appreciated...

-Allen
 
when I


Code:
$current_dir = &quot;/public_html/reports/pi/&quot;;
$path = &quot;reports/pi/&quot;;
$dir = opendir($current_dir);

echo (&quot;<br><hr width=225 align=left>pi<br>&quot;);
// write file names to array

$list = array (  while ($file = readdir($dir))  array(&quot;file&quot; => &quot;$file&quot;) );
// sort array

sort ($list);
// display sorted array as links

foreach ($list as $key=>$value){ print(&quot;$value&quot;);}


I must be doing something wrong, as I get a parse error on the line:
Code:
$list = array (  while ($file = readdir($dir))  array(&quot;file&quot; => &quot;$file&quot;) );

ideas?

 

That is what I found in my O'Reilly book... Thanks...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top