开发者

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜