Jump to content


Photo

How do I sort?


  • Please log in to reply
1 reply to this topic

#1 kat2481

kat2481
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 14 March 2006 - 11:54 PM

How do I sort this so it displays the results alpha?

if ($handle = opendir("/home/mysite/public_html/Store/{$thestore}/Images/")) {
//echo "Directory handle: $handle\n";
//echo "Files:\n";


while (false !== ($file = readdir($handle))) {
if (strlen($file) >3){

echo "<OPTION Value = '";
echo "Store/{$thestore}/Images/{$file}";


echo "'>";
echo "$file";
echo "</OPTION>";
}
}



closedir($handle);
}

if ($handle = opendir("/home/mysite/public_html/Images/Backgrounds/")) {
//echo "Directory handle: $handle\n";
//echo "Files:\n";


while (false !== ($file = readdir($handle))) {
if (strlen($file) >3){
echo "<OPTION Value = '";
echo "Images/Backgrounds/{$file}";

echo "'>";
echo "$file";
echo "</OPTION>";
}
}



closedir($handle);
}
?>


--------
Thanks for any replies

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 15 March 2006 - 12:12 AM

This should help.

if ($handle = opendir("/home/mysite/public_html/Store/{$thestore}/Images/")) {
    while ($file = readdir($handle)) {
        if (strlen($file) >3){
            $files[] = $file;
        }
    }
    closedir($handle);
    
    sort($files);
    foreach ($files as $file) {
        echo "<OPTION value=\"Store/{$thestore}/Images/{$file}\">$file</OPTION>";
    }
}

if ($handle = opendir("/home/mysite/public_html/Images/Backgrounds/")) {
    ...same as above...
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users