Forum Moderators: coopster
$result = mysql_query ($query);
echo "<select name=mon_2 value=''>Contact Name</option>";
// printing the list box select command
while($nt=mysql_fetch_array($result)){
//Array or records stored in $nt
echo "<option value='$nt[name]'>$nt[name]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
If you want the first option in the list to be 'Contact Name', then you could do this:
$result = mysql_query ($query);
echo "<select name='mon_2'><option value='Contact Name'>Contact Name</option>";
while($nt=mysql_fetch_array($result)){
echo "<option value='$nt[name]'>$nt[name]</option>";
}
echo "</select>";
However, if 'Contact Name' is in the MySql result set, it will show up twice. To have it in there once and automatically selected, try this:
$result = mysql_query ($query);
echo "<select name='mon_2'>";
while($nt=mysql_fetch_array($result)){
echo "<option value='$nt[name]'";
if($nt[name] == 'Contact Name') { echo " selected"; }
echo ">$nt[name]</option>";
}
echo "</select>";
Chad