BillyBoB Posted July 13, 2006 Share Posted July 13, 2006 does anybody know how to order a list by the alphbet Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 13, 2006 Share Posted July 13, 2006 If you're using MySQL, just add the "order by" clause at the end of the select statement.Ken Quote Link to comment Share on other sites More sharing options...
ShogunWarrior Posted July 13, 2006 Share Posted July 13, 2006 Or if it's an array of values then simply:[code]sort($arrayName);[/code]Now arrayName will be sorted alphabetically, magic. Quote Link to comment Share on other sites More sharing options...
pixy Posted July 13, 2006 Share Posted July 13, 2006 SELECT column FROM table [b]ORDER BY column[/b]You can also use group by to further organize the data. Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 14, 2006 Share Posted July 14, 2006 a note about sort: it doesn't sort the items alphabetically as one would expect, even if you specify comparison as strings. in the case that you want array items sorted as a human would alphabetically sort them, use natsort() or natcasesort() (the latter being a case-insensitive version of the natural sort).and yes, i know this post has strayed off-topic, but i figured i'd point it out while sort() was being mentioned. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 14, 2006 Share Posted July 14, 2006 Out of interest, how does it sort them then? Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 14, 2006 Share Posted July 14, 2006 i couldn't really tell, it was a little erratic. i had an array of filenames, of which a few started with numbers, others with upper case and others with lower case. i believe it processed them in the order of number in numeric order, upper case in alpha order, lowercase in alpha order. i was using sort($array, SORT_STRING).i ended up using natcasesort(), and it fixed the issue. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 14, 2006 Share Posted July 14, 2006 Ah ok, looks like the manual says pretty much the same:[quote]Warning Be careful when sorting arrays with mixed types values because sort() can produce unpredictable results. [/quote]Looks like sort would do the job for just text though. Quote Link to comment Share on other sites More sharing options...
akitchin Posted July 14, 2006 Share Posted July 14, 2006 well they were all in string format, so there were no mixed types. Quote Link to comment 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.