1

这段代码:

while ($row = mysql_fetch_assoc($result)) {

    $username=$row["username"];
    $currentroles[$username]=$row["role"];

    print "abc";

    echo "<tr><td>$username</td>";

    echo "def";

    echo "<td><select name=\"role[$username]\">";

    if($row["role"]=='admin')
    {
        echo "<option value=\"admin\">admin</option>";
        echo "<option value=\"user\">user</option>";
    }
    else if($row["role"]=='user')
    {
        echo "<option value=\"user\">user</option>";
        echo "<option value=\"admin\">admin</option>";
    }

   echo "</select></td></tr><br/>";
}

生成此页面:

代码生成的页面

(这只是页面的一部分,下拉列表的用户数量与“abcdef”一样多)

我不知道为什么页面顶部的“abc”、“def”字符串。如果我把它们拿出来,页面中有空行(而不是“abcdef)”,即使我从未打印过<br>. 这是怎么回事?

4

2 回答 2

4

发生这种情况是因为它们打印在表格中,但在标签<tr><td>. 此文本显示在表格之前。例如:

<table>
  <tr>
    <td>a</td>
  </tr>
  b
  <tr>
    <td>c</td>
  </tr>
</table>

看起来像

b

一个

C

于 2013-09-18T09:29:40.260 回答
3

字符串abcdef呈现在页面顶部,因为它们不在您的表格中。将它们放入某个单元格中<td>,它将解决您的问题 - 文本将在表格中。

于 2013-09-18T09:26:56.073 回答