aabbbiee Posted July 23, 2008 Share Posted July 23, 2008 I am customizing an unsupported third-party open-source tool called Dropproof to make it look nicer, and I've run into an issue that my rudimentary PHP skills can't puzzle out. I did do some searches for this but couldn't find anything. http://www.abbiebrownphoto.com/dropproof/denise2/ If you click on the link above, you can see that it displays pictures from a directory on my server in an array. For some reason, they are not displaying in any order (that I can tell). I'd like them to be in filename order. The original version of the tool also has this problem, so I didn't cause it from my slash-and-burn design work. Here is the section of code that is called for this array. <? for ($i=0; $i<count($images); $i++) { $img = $images[$i]; ?> <div class="img"> <p><a href="javascript:;" onclick="loadDetail('<?=$img?>','<?=$i?>')"><img src="proofs/thumbs/<?=$img?>" alt="<?=$img?>" border="0" /></a></p> <p><?=$img?></p> </div> <? } ?> I use Bluehost as a host if that's any help to you. Current version is PHP 5. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/116297-solved-randomly-displayed-array-how-to-order/ Share on other sites More sharing options...
.josh Posted July 23, 2008 Share Posted July 23, 2008 before your loop, sort($images) Quote Link to comment https://forums.phpfreaks.com/topic/116297-solved-randomly-displayed-array-how-to-order/#findComment-598024 Share on other sites More sharing options...
GingerRobot Posted July 23, 2008 Share Posted July 23, 2008 Judging from your image names, you might want natsort(). Quote Link to comment https://forums.phpfreaks.com/topic/116297-solved-randomly-displayed-array-how-to-order/#findComment-598028 Share on other sites More sharing options...
aabbbiee Posted July 23, 2008 Author Share Posted July 23, 2008 Wow, thank you so much! sort() works; natsort() did not work. I don't know why, but I will read up. I really appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/116297-solved-randomly-displayed-array-how-to-order/#findComment-598031 Share on other sites More sharing options...
aabbbiee Posted July 23, 2008 Author Share Posted July 23, 2008 Apparently the underscores in my naming conventions cause problems with natsort(). I will continue to just rename with the extra 00s to make up for the problem. Again, thank you for the answers! Quote Link to comment https://forums.phpfreaks.com/topic/116297-solved-randomly-displayed-array-how-to-order/#findComment-598040 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.