为什么我在这个WHERE循环的输出中得到了中断


Why am I getting a break in the output of this WHERE loop?

我为我正在制作的游戏做了一个WHILE循环,看起来像这样:更新为完整的IF语句

if ($switch == 0){
echo '<a href="/index.php">Exit Voting Booth - You May Vote Again Later</a></br>';
echo '<div role="main" id="main"><div class="wrapper">';
echo '<h3>Ballot Questions:</h3></br>';
$query = "SELECT * FROM ballot_questions";
$ballots = mysql_query($query,$link) or die("Unable to select: ".mysql_error());
$x = 1;
//echo $x;
while($row = mysql_fetch_array($ballots))
{
echo '<h4>'.$row['question'].'<form action="vote_engine.php" method="post">
<input type="hidden" name="id" value= "',$id,'">
Yes:<input type="radio" value="yes" name = "',$x,'">
No:<input type="radio" value="no" name = "',$x,'"></h4></br>';
$x++;
//echo $x;
}
echo '<p><input type="submit" value="submit" name="submit">
</form></p>';
}

在浏览器中显示如下:

测试选票问题1

是否

测试选票问题2是否

测试选票问题3是否

测试选票问题4是否

第一行总是显示得好像有一个/br标记。其余的我想怎么说就怎么说。

这是html输出:

退出投票亭-您稍后可以再次投票

选票问题:

测试选票问题#1是:否:测试选票问题#2是:否;测试选票问题#3是:否,测试选票问题#4是:否

有什么想法吗?感谢

这根本不能生成有效的HTML。谁知道浏览器会如何呈现这个页面。

我马上就看到两件事:

  1. 您的<br>标记不正确
  2. 您正在开始一堆表单,然后结束这些标签一次

你可以用这个代码修复这些:

<?php
if ($switch == 0) {
    echo '<a href="/index.php">Exit Voting Booth - You May Vote Again Later</a></br>';
    echo '<div role="main" id="main"><div class="wrapper">';
    echo '<h3>Ballot Questions:</h3><br />'; ; // This was </br>
    $query = "SELECT * FROM ballot_questions";
    $ballots = mysql_query($query, $link) or die("Unable to select: " . mysql_error());
    $x = 1;
    echo '<form action="vote_engine.php" method="post">'; // This will create ONE form
    while ($row = mysql_fetch_array($ballots)) {
        echo '<h4>' . $row['question'] . '<input type="hidden" name="id" value= "', $id, '">
                Yes:<input type="radio" value="yes" name = "', $x, '">
                No:<input type="radio" value="no" name = "', $x, '">
              </h4>
            <br />'; // This was </br>
        $x++;
    }
    echo '<p><input type="submit" value="submit" name="submit"></p></form>'; // Switch </p> and </form> tags
}
?>