pooker Posted July 4, 2008 Share Posted July 4, 2008 here is some of my basic code while($folder = readdir($dir) ){ if ($folder != '.' && $folder != '..') { $number = $number +1; ?> <option value="<? echo $folder ?>">chapter <? echo $number ?></option> <? } } in the next page it uses echo folder to reference the image like this img src = /mangareadr/$series/$folder/$number.png dont worry about the way the code looks because I was just wrighting a short example, and the code works with passing and everything my problem is the way it readdir reads the folder. In the folder here is how it is setup chapter1 chapter2 chapter3 etc,.... So you would assum it would read it like that right? Well it doesn't, readdir reads mine backwords for some reason so if a user clicks on chapter 4 it would give them chapter 1, chapter 3 would give them chapter 2 and so on in reverse order. Because I used the number incrementer to increase in number I thought this would work but it does not. Hop that is clear and thanks for the help ^^ Link to comment https://forums.phpfreaks.com/topic/113169-does-readdir-not-read-it-in-numerical-order/ Share on other sites More sharing options...
LooieENG Posted July 4, 2008 Share Posted July 4, 2008 You could use sort() Loop through, and add each file to an array, and then use sort() http://uk.php.net/sort Link to comment https://forums.phpfreaks.com/topic/113169-does-readdir-not-read-it-in-numerical-order/#findComment-581430 Share on other sites More sharing options...
PFMaBiSmAd Posted July 4, 2008 Share Posted July 4, 2008 readdir() returns files in the order they are in in the file system. To get a sorted list, either read the file names in to an array and sort them or use the glob() function, which sorts the results for you. Link to comment https://forums.phpfreaks.com/topic/113169-does-readdir-not-read-it-in-numerical-order/#findComment-581513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.