Jen you're in luck I had to teach myself to do the same thing because I wanted to make a dynamic pull down menu. The trick is to put the variables into a dynamically generated output and then have them sorted. Since you're doing from a database I'll go ahead and give you a copy of the code I used to give you a general idea.
// Check for Link Selection
$db_connect = mysql_connect ( $server, $username, $password )
or die ( 'Unable to connect to database!' );
mysql_select_db ( $database, $db_connect )
or die ( 'Unable to select database!' );
$query = "SELECT * FROM links";
$results = mysql_query ($query)
or die ( 'Unable to execute query!' );
while ( $row = mysql_fetch_array( $results ))
{
$name = $row["NAME"];
$link = $row["LINK"];
$option_block .= "\t<option value=\"$link\">$name</option>\n";
}
Ok this is what the code does. It connects to a desired database then looks in the table for the field named NAME and LINK it then crabs the data and sorts them individually like this. You can change the $option_block to anything you wish and it will work. I hope this helps you, If not go ahead and e-mail me and I will help you further my e-mail address is on my site which is in my signature.