Page 1 of 1

Sort alphabetically

Posted: Fri Jan 16, 2009 12:27 pm
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

Re: Sort alphabetically

Posted: Fri Jan 16, 2009 1:20 pm
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

Re: Sort alphabetically

Posted: Fri Jan 16, 2009 1:27 pm
by Burrito
why not just have MySQL sort it for you on your select statement?

Re: Sort alphabetically

Posted: Fri Jan 16, 2009 1:31 pm
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.