while循环中的打印文本无法按预期运行

This code:

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/>";
}

Produces this page:

page produced by the code

(this is just a part of the page, there are as many users with a dropdown list as "abcdef"s)

I have no idea why are the "abc", "def" strings at the top of the page. If I take them out, there are empty lines in the page (instead of "abcdef)", even though I never printed <br>. What's going on?

This happens because they are printed in table but between tags <tr> and <td>. This text is displayed before table. For example:

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

will looke like

b

a

c

The strings abc and def are rendered on the top of your page because they are not in your table. Put them into some cell <td> and it will solve your problem - text will be in the table.