Jump to content


Photo

how to order the usernames out of a table by the alphbet


  • Please log in to reply
8 replies to this topic

#1 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 13 July 2006 - 10:21 PM

does anybody know how to order a list by the alphbet



#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 July 2006 - 10:23 PM

If you're using MySQL, just add the "order by" clause at the end of the select statement.

Ken

#3 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 13 July 2006 - 10:27 PM

Or if it's an array of values then simply:
sort($arrayName);
Now arrayName will be sorted alphabetically, magic.
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#4 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 13 July 2006 - 10:33 PM

SELECT column FROM table ORDER BY column
You can also use group by to further organize the data.

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#5 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 14 July 2006 - 05:27 PM

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.

#6 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 14 July 2006 - 05:29 PM

Out of interest, how does it sort them then?

#7 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 14 July 2006 - 05:41 PM

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.

#8 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 14 July 2006 - 05:44 PM

Ah ok, looks like the manual says pretty much the same:

Warning
Be careful when sorting arrays with mixed types values because sort() can produce unpredictable results.


Looks like sort would do the job for just text though.

#9 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 14 July 2006 - 06:01 PM

well they were all in string format, so there were no mixed types.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users