Sort function - drop down menu

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
jb
Forum Newbie
Posts: 5
Joined: Tue Mar 02, 2004 9:11 am

Sort function - drop down menu

Post 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.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

$query = "SELECT * FROM name ORDER BY surname";
jb
Forum Newbie
Posts: 5
Joined: Tue Mar 02, 2004 9:11 am

Post by jb »

Many thanks! :)
Post Reply