Re: [PHP] sort()-help needed

2002-08-20 Thread Rasmus Lerdorf

Put them into an array and sort() the array.  The loop through the sorted
array and output at that point.

-Rasmus

On Wed, 21 Aug 2002, Øystein Håland wrote:

 When calling the function createLinks() I get an unsorted result, and that's
 NOT what I want. But I'm not able (lack of knowlegde) to sort the output
 (the links).

  ?php
 function createLinks() {
  $handle=opendir(.);
  echo UL\n;
  while ($file = readdir($handle)){
   if (($file == .) || ($file == ..) || ($file == index.php) || ($file
 == basename ($PHP_SELF))) { continue; }
   if(is_file($file)) {
$linktext = ucfirst ($file);
$linktext = substr_replace ($linktext,'',-4);
echo LInbsp;nbsp;A HREF=\$file\$linktext/A\n;
   }
  }
  echo /UL\n;

  return true;
 }
 ?



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] sort()-help needed

2002-08-20 Thread Øystein Håland

Put them into an array and sort() the array.  The loop through the sorted
array and output at that point.

Just what I try. But, because of my lack of understanding, the output is my
problem:

function createLinks() {
 $p = 0;
 $handle=opendir(.);
 echo UL\n;
 while ($file = readdir($handle)){
  $files[] = $file;
  $sorted = sort($files);
  if (($file == .) || ($file == ..) || ($file == basename ($PHP_SELF)))
{ continue; }
  if(is_file($file)) {
$p++;
   $linktext = ucfirst ($file);
$linktext = substr_replace ($linktext,'',-4);
   echo LIA HREF=\$file\$linktext/A\n;
  }
 for($i = 0; $i  $p; $i++) {
//something here
 }
 echo /UL\n;
 return true;
}
?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] sort()-help needed

2002-08-20 Thread Jason Wong

On Wednesday 21 August 2002 06:41, Øystein Håland wrote:
 Put them into an array and sort() the array.  The loop through the sorted
 array and output at that point.

 Just what I try. But, because of my lack of understanding, the output is my
 problem:


You're not doing what has been suggested above. See comments below.

1) In your while loop only read in the filenames into an array (discarding '.' 
and '..').

2) Then sort the array.

3) Then use a foreach to loop through the array elements to create the links.

 function createLinks() {
  $p = 0;
  $handle=opendir(.);
  echo UL\n;
  while ($file = readdir($handle)){
You've read in a filename

   $files[] = $file;
And added it to the array

   $sorted = sort($files);
Then sort the array, but why? You haven't read in ALL the files yet so why 
sort now? Also you're not using the results of the sorted filenames ($sorted) 
anywhere else in your code.


-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
The Anglo-Saxon conscience does not prevent the Anglo-Saxon from
sinning, it merely prevents him from enjoying his sin.
--Salvador De Madariaga
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php