Jump to content

Archived

This topic is now archived and is closed to further replies.

BillyBoB

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

Recommended Posts

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

Ken

Share this post


Link to post
Share on other sites
Or if it's an array of values then simply:
[code]
sort($arrayName);
[/code]
Now arrayName will be sorted alphabetically, magic.

Share this post


Link to post
Share on other sites
SELECT column FROM table [b]ORDER BY column[/b]
You can also use group by to further organize the data.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
well they were all in string format, so there were no mixed types.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.