Sort alphabetically

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Sort alphabetically

Post by oscardog »

So i use the following line to get the data, they choose a letter to search from and it selects all games starting with that letter:

Code: Select all

$result = mysql_query("SELECT * FROM games WHERE startletter = '".$lettersort."'");
Now at the moment it just sorts it using the ID, so basically what order they were put into the database. I want to sort it so they appear alphabetically, i had a look at the sort function but wasnt sure how to get the result ito an array so if someone wants to explain...

EDIT: Just looked at my code and i do have the 'mysql_fetch_array' so that means $result is infact an array, now what do i do to sort that?

Thanks!

Oscardog
scaraffe
Forum Newbie
Posts: 3
Joined: Fri Jan 16, 2009 1:06 pm

Re: Sort alphabetically

Post by scaraffe »

You can sort arrays in using sort() functions. I would recommend you to see this tutorial http://www.developertutorials.com/tutor ... page1.html
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: Sort alphabetically

Post by Burrito »

why not just have MySQL sort it for you on your select statement?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Sort alphabetically

Post by RobertGonzalez »

Burrito wrote:why not just have MySQL sort it for you on your select statement?
+1. ORDER BY would be what you are looking for in this case.
Post Reply