0

我已经看到了一个答案,但我不明白 - 问号在哪里(在第 6 行)?看了一会,想必有人舌尖上已经有了答案。- (是的,我知道我在我的代码中混合了转义字符,但我正在尝试创建更清晰/更好的代码,我可能不应该混合 PHP 和 HTML)

  <select name="teacher"> ';
        $empquery = "SELECT * FROM `employees` ORDER BY `lastname`";
        $empresults = $pdo->query($empquery);
        while ($emprow = $empresults->fetch()) {
            echo "<option value=".$emprow['id'];
            if (?????????? == $emprow['id']) 
                echo "selected = 'selected'";   
            echo "> {$emprow['lastname']} {$emprow['firstname']}</option> ";    
        } 
  echo ' </select>
4

2 回答 2

0

正如vodich建议的那样,应该有另一个变量保存当前值或选定值

例如

如果要为部门分配联系人,您可能希望将该部门的联系人(如果已经有)与选择列表选项值进行比较

于 2013-01-03T20:34:13.787 回答
0

Oh... I just got it - Apologies for lameness of question. For those who come after me:

In my case, the variable in the ???? should be the one that held a value when the user is sent to this web page in the FIRST place. I had a page where a classroom was selected, then this page loads the classroom info. The classroom info along with a teacher ID was sent to this form.

This form allows the user to select a different teacher for the classroom. The default (selected="selected") value is in that variable (array) I sent to this page.

Thanks for explaining guys.

于 2013-01-03T20:40:47.843 回答