Shamrox Posted January 17, 2007 Share Posted January 17, 2007 Alright, I've got this drop down working where it pulls all the files in. Is there a way to sort them alphabetically?Here's the code. Thanks for the assist.[code]><select name='filename' id='filename'> <?phpif ($handle = opendir('/path/to/the/options_sheets')) { /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo "<option value='$file\n'>$file\n</option>"; } } closedir($handle);}?></select>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34623-sorting-directory-list-in-dropdown/ Share on other sites More sharing options...
dgiberson Posted January 17, 2007 Share Posted January 17, 2007 You could load all the file names into an array, then sort the array.... Quote Link to comment https://forums.phpfreaks.com/topic/34623-sorting-directory-list-in-dropdown/#findComment-163153 Share on other sites More sharing options...
ted_chou12 Posted January 18, 2007 Share Posted January 18, 2007 just to let you know, $files[] = $filenamethis has to be used within a loop...(above)and there are a lot of different sorts, the basic ones aresort()sorts alphebitcallyandrsort()oppisite sort()but these two are case sensitive, for none case sensitive sorts, natcasort() would be a better choice...Ted Quote Link to comment https://forums.phpfreaks.com/topic/34623-sorting-directory-list-in-dropdown/#findComment-163697 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.