0

这是我在编辑页面中的多重选择下拉框。这里的问题是这只显示一个选定的项目。它不会显示其中的所有选定项目。我该如何纠正这个?

    <?php
         $query="SELECT * FROM lab";
        $dropdown = "<select name='labid[]' multiple='multiple'  style='height:80px;' size='5' id='lab'>";
        //$dropdown .= "<option value=''>Select lab to assign </option>";
        $result2 = mysql_query ($query);
        while($row2 = mysql_fetch_assoc($result2)) 
        {

  $dropdown .= "\r\n<option value='{$row2['lab_id']}'";
            while($row1 = mysql_fetch_assoc($result1)) 
              {
                 if(($row1['lab_id'])==($row2['lab_id']))
                  {
                      $dropdown .=" selected='selected'";
                  }
             }
  $dropdown .= ">{$row2['l_name']}</option>";
        }
        $dropdown .= "\r\n</select>";
        echo $dropdown;
       ?>
4

1 回答 1

0

尝试将 while 循环更改为 foreach 循环。

改变

 while($row2 = mysql_fetch_assoc($result2)) 

foreach(mysql_fetch_assoc($result2) as $row2)

 while($row1 = mysql_fetch_assoc($result1)) 

foreach(mysql_fetch_assoc($result1) as $row1)
于 2012-07-20T07:48:42.207 回答