RE: [PHP] Sort a an array?
| From: | Jon Haworth | Date: | Thu, 16 Aug 2001 15:47:50 +0000 |
| Subject: | RE: [PHP] Sort a an array? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-63048@lists.php.net to get a copy of this message | ||
The best way to do this, which is conveniently also the easiest, is to do it
within your SQL query.
$table = "tablename";
$field = "fieldname";
$query = "select * from $table order by $field";
or, for descending sort:
$query = "select * from $table order by $field desc";
HTH
Jon
-----Original Message-----
From: Allen May [mailto:umayxa3@donet.com]
Sent: 16 August 2001 16:32
To: php-general@lists.php.net
Subject: [PHP] Sort a an array?
I want to sort a result set from a mySQL query (see code below).
I can't figure out how to properly sort the $result in the while loop.
I just want to alphabatize the search result.
Any suggestions how to do this?
Thanks
-Allen
umayxa3@donet_nospam.com (remove _nospam to reply)
*************************************************************************
$query = "select * from $table";
$result = mysql_query($query);
print "<form name=\"JobDesc\" method=\"post\"
action=\"jobdesc.php\">\n";
print "<select name=\"wilber\">\n";
while ($row = mysql_fetch_array($result)) :
print "<option value=\"";
print $row["Jobtitle"];
print "\">";
print $row["Jobtitle"];
print "</option>\n";
endwhile;