PHP and selected option menu
Hello I created a menu from a table.开发者_如何学JAVA I added to the table employee the user none to make it the default value in the option menu. The problem is that I dont know how to add the none user as the default value in the option menu. Here is what I have:
$query = "SELECT UserName FROM employee where Classification_ClassificationID = '2'";
$result = queryMysql($query);
if (!queryMysql($query)) {
"Query fail: $query<br />" .
mysql_error() . "<br /><br />";
}
else
{
<select name = "UserName", "Name" size = "1">'; // or name="toinsert[]"
while ($row = mysql_fetch_array($result)) {
'<option value="' . htmlspecialchars($row['UserName']) . '" >'
. htmlspecialchars($row['UserName'])
. '</option>';
echo <option selected="selected">Non User</option>
before the while loop. Also read comments @Cybernate .
<select>
<?php
if (!queryMysql($query)) {
"Query fail: $query<br />" . mysql_error() . "<br /><br />";
}
else
{
while ($row = mysql_fetch_array($result)) {
$selected = '';
if($row['Username']=='none') $selected = ' selected="selected"';
echo '<option value="'.htmlspecialchars($row['UserName']).'"'.$selected.'>'.htmlspecialchars($row['UserName']).'</option>';
}
}
?>
</select>
精彩评论