Wednesday, 18 September 2013

Printed text in while loop doesn't act as expected

Printed text in while loop doesn't act as expected

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:

(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?

No comments:

Post a Comment