我想使用 php 从数据库中以表格形式输出数据。& 在表格中使用其他颜色
但它不显示替代颜色,浏览器在 php 代码开始之前制作 div 标签,因此颜色不显示。
部分代码:
$result = mysqli_query($con, "SELECT * FROM form1 ORDER by id ");
echo "<table border=1>
<tr>
<th>id</th>
<th>Name</th>
<th>userName</th>
<th>e-Mail id</th>";
while ($row = mysqli_fetch_array($result)) {
if ($row['id'] % 2 == 1) {
echo '<div class = "odd">';
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['mail'] . "</td>";
echo "</tr>";
echo '</div>';
} else {
echo '<div class = "even">';
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['mail'] . "</td>";
echo "</tr>";
echo '</div>';
}
}
echo "</table>";