我在表行<tr>
内明确插入了4列,但是我看到一个多余的东西弄乱了我的表设计。添加了图像here,这必须是我第一次从数据库中获取数据。这将是php / html标记:
<form action="test.php" method="GET">
<?php
$query = "SELECT data0, data1, data2, data3 FROM table_name";
$result = mysqli_query($conn, $query);
echo "<table>";
echo "<tr>
<th>Info-1</th>
<th>Info-2</th>
<th>Info-3<th>
<th>Info-4</th>
</tr>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>
<td>{$row['data0']}</td>
<td>{$row['data1']}</td>
<td>{$row['data2']}</td>
<td>{$row['data3']}</td>
</tr>";
} ?>
答案 0 :(得分:0)
在PHP标记内使用PHP代码。不要用PHP弄乱HTML标记。如果您遵循这样的做法,就可以避免类似的错误
<?php
$query = "SELECT data0, data1, data2, data3 FROM table_name";
$result = mysqli_query($conn, $query); ?>
<table>
<tr>
<th>Info-1</th>
<th>Info-2</th>
<th>Info-3</th> // you are missing close tag here.
<th>Info-4</th>
</tr>
<?php while($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<td><?php echo $row['data0']; ?></td>
<td><?php echo $row['data1']; ?></td>
<td><?php echo $row['data2']; ?></td>
<td><?php echo $row['data3']; ?></td>
</tr>
<?php } ?>