BillyBoB Posted July 13, 2006 Share Posted July 13, 2006 does anybody know how to order a list by the alphbet Link to comment https://forums.phpfreaks.com/topic/14535-how-to-order-the-usernames-out-of-a-table-by-the-alphbet/ 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 Link to comment https://forums.phpfreaks.com/topic/14535-how-to-order-the-usernames-out-of-a-table-by-the-alphbet/#findComment-57632 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. Link to comment https://forums.phpfreaks.com/topic/14535-how-to-order-the-usernames-out-of-a-table-by-the-alphbet/#findComment-57634 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. Link to comment https://forums.phpfreaks.com/topic/14535-how-to-order-the-usernames-out-of-a-table-by-the-alphbet/#findComment-57636 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. Link to comment https://forums.phpfreaks.com/topic/14535-how-to-order-the-usernames-out-of-a-table-by-the-alphbet/#findComment-58028 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? Link to comment https://forums.phpfreaks.com/topic/14535-how-to-order-the-usernames-out-of-a-table-by-the-alphbet/#findComment-58030 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. Link to comment https://forums.phpfreaks.com/topic/14535-how-to-order-the-usernames-out-of-a-table-by-the-alphbet/#findComment-58040 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. Link to comment https://forums.phpfreaks.com/topic/14535-how-to-order-the-usernames-out-of-a-table-by-the-alphbet/#findComment-58042 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. Link to comment https://forums.phpfreaks.com/topic/14535-how-to-order-the-usernames-out-of-a-table-by-the-alphbet/#findComment-58046 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.