system — 2011-09-21T08:31:49-04:00 — #1
Hi, I need a simple solution to sort an array alphabetically, here is my code:
<option value="<?=$cities['grd']?>"> <?=$cities['grd']?></option>
As you can see I added the sort function, but doesnt work.. any ideas?
parkint — 2011-09-21T08:35:20-04:00 — #2
I found this, at the top of the list, of a quick Google search: http://www.w3schools.com/php/func_array_sort.asp
Even the example sorts a set of strings alphabetically.
system — 2011-09-21T08:36:31-04:00 — #3
hi thanks for that.. as you can see I added the sort function .. but it doesn't seem to sort alphabetically.. what I am doing wrong?
starlion — 2011-09-21T08:54:14-04:00 — #4
You're trying to do too much in one line. Make your while pull the array, then sort it inside the loop.
michael_morris1 — 2011-09-21T09:07:20-04:00 — #5
Since you are pulling from the database make the database do the sorting with an ORDER BY clause.
SELECT grd FROM cities ORDER BY grd DESC
Under normal circumstances SQL can sort considerably faster than PHP, so it is more efficient to use SQL ordering at query time.