Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- revisiting older topic- drop down menu email


Matthew1980 - 9:38 pm on Dec 22, 2011 (gmt 0)


Hi there Gilead,

You're so close! Order by is the correct syntax to use, and this will sort the chosen field (in this case FirstName) into alphabetical order either ASCending or DESCending, so you'll need to alter that variable accordingly:-

$query = "SELECT `contactid`, `firstname`, `lastname` FROM `".$table_name."` ORDER BY `firstname` DESC";

$sql = mysql_query($query);

echo "<select name=\"ContactID\">";

while ($row=mysql_fetch_assoc($sql)){

$id = htmlentities($row['contactid']);
$firstname = htmlentities($row['firstname']);
$lastname = htmlentities($row['lastname']);
echo "<option value = "\".$id."\" >";
echo $firstname." ".$lastname; //optional space between the names
echo "</option>";

}
echo "</select>";
?>

I've reformatted the way the concatenations were done so that everything is uniform - good coding practice..

Hopefully if you run this now you'll get the results as you're expecting.

Cheers,
MRb


Thread source:: http://www.webmasterworld.com/php/4400637.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com