我的PHP和HTML代码用于从MySQL数据库中获取数据并将其显示在通过while循环运行的表中,但是在表标记开始并且h3标记结束之前会输出随机分号(通过inspect查看)浏览器中的元素)。输出的分号数与SQL查询中的行数相匹配。
echo "<form action='predictions.php' method='POST'>";
echo "<h3>" . $date[0] . "</h3>
<table>
<tr>
<col width='100'>
<col width='50'>
<col width='50'>
<col width='100'>
<col width='70'>
<col width='100'>
<th>Home <br> Team</th>
<th>Home <br> Score</th>
<th>Away <br> Score</th>
<th>Away <br> Team</th>
<th>Match <br> Time </th>
<th>First <br> Scorer </th>
</tr>";
while($row = mysqli_fetch_row($match) and $matchid = mysqli_fetch_array($sqlmatchid)){
if ($date[0] != $row[3]) {
echo "</table>";
echo "<hr>";
$date[0] = $row[3];
echo "<h3>".$date[0]."</h3>
<table>
<tr>
<col width='100'>
<col width='50'>
<col width='50'>
<col width='100'>
<col width='70'>
<col width='100'>
<th>Home <br> Team</th>
<th>Home <br> Score</th>
<th>Away <br> Score</th>
<th>Away <br> Team</th>
<th>Match <br> Time </th>
<th>First <br> Scorer </th>
</tr>";
}
echo "<tr>";
echo "<td>" . $row[0] . "</td>" ?>
<td> <input id='phs' type='text' name=<?php echo "phs".$matchid['MatchID'] ?> size='1' maxlength='1'> </td>
<td> <input id='pas' type='text' name=<?php echo "pas".$matchid['MatchID'] ?> size='1' maxlength='1'> </td>
<?php
$smatchid = $matchid['MatchID']; //match id to find scorer
echo "<td>" . $row[1] . "</td>";
echo "<td>" . $row[2] . "</td>" ?>
<td> <select id="scorer" name=<?php echo "scorer".$matchid['MatchID'] ?>>
<option> </option>
<?php
$result = mysqli_query($con,"SELECT PlayerName
FROM players, matches
WHERE matches.MatchID = '$smatchid' AND (players.TeamID = matches.HTeamID OR players.TeamID = matches.ATeamID)");
while ($row = mysqli_fetch_row($result)){
echo "<option> $row[0] </option>";
}
?>
</select> </td>;
<?php
echo "</tr>";
}
我不明白为什么会出现这些分号并想删除它们。
答案 0 :(得分:1)
分号即将到来,因为你已经写了</select> </td>;
。 </td>
每次生成分号后的分号。从那里删除它。