brooksh Posted February 11, 2008 Share Posted February 11, 2008 I am trying to sort my images by file name, but it is out of place. How can I sort it in order? This is how it sorts, how can I change it to go from 1-12? image_1.jpg image_10.jpg image_11.jpg image_12.jpg image_2.jpg image_3.jpg image_4.jpg image_5.jpg image_6.jpg image_7.jpg image_8.jpg image_9.jpg Link to comment https://forums.phpfreaks.com/topic/90544-sort-by-name-problem/ Share on other sites More sharing options...
cooldude832 Posted February 11, 2008 Share Posted February 11, 2008 technically they are sorted by name. You are trying to sort by some integer value so you are going to need a sorting function basically you want to take that integer off the keys (maybe explode) and then sort the array based on those values Look at a sorting function Link to comment https://forums.phpfreaks.com/topic/90544-sort-by-name-problem/#findComment-464211 Share on other sites More sharing options...
PFMaBiSmAd Posted February 11, 2008 Share Posted February 11, 2008 You don't state where these value are, but if they are in an array - http://php.net/natsort Link to comment https://forums.phpfreaks.com/topic/90544-sort-by-name-problem/#findComment-464216 Share on other sites More sharing options...
brooksh Posted February 11, 2008 Author Share Posted February 11, 2008 This is the sql $sql = "SELECT imagename FROM images WHERE id = '$id' order by imagename"; Link to comment https://forums.phpfreaks.com/topic/90544-sort-by-name-problem/#findComment-464218 Share on other sites More sharing options...
revraz Posted February 11, 2008 Share Posted February 11, 2008 Use leading 0's in front of the single digits. image_01.jpg Link to comment https://forums.phpfreaks.com/topic/90544-sort-by-name-problem/#findComment-464226 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.