Page 1 of 1

Sort function - drop down menu

Posted: Tue Mar 02, 2004 9:11 am
by jb
I have successfully created a dynamic drop down menu using the following code and it works fine:

$query = "SELECT * FROM name";
$result = mysql_query($query);
while ($record = mysql_fetch_assoc($result)) {
echo "<OPTION VALUE = '".$record["staffID"]."'>".$record["surname"].', '.$record["forename"];
}

However, I want the records returned to be in alphabetical order in relation to "surname". I think I need to use the sort function but all attempts have failed.

If anyone has the answer I would be very grateful.

Posted: Tue Mar 02, 2004 9:12 am
by markl999
$query = "SELECT * FROM name ORDER BY surname";

Posted: Tue Mar 02, 2004 9:20 am
by jb
Many thanks! :)