我使用简单的 AJAX 来显示数据库中的数据。但是,当我运行它时,我的表上只显示 1 个数据,其余数据显示在我的表之外。我错过了什么吗?
我使用我的标准 Bootstrap 表中的相同代码,它正确地将数据显示到我的表中,但不是这个。
我的 PHP 文件
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "tata_kota1";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * from laporan_gini";
$result = $conn->query($sql);
echo "<table border='1'>
<thead>
<tr>
<th>Nomor</th>
<th><b>tipe variabel</b></th>
<th><b>variabel turunan</b></th>
<th><b>nama atahun</b></td></th>
<th><b>turunan tahun</b></td></th>
<th><b>data_content</b></td></th>
<th><b>vertical variabel</b></th>
</tr>
</thead>";
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
{
echo "<tbody><tr>";
echo "<th>".$row['id']."</th>";
echo "<td>".$row['nama_variabel']."</td>";
echo "<td>".$row['nama_variabel_turunan']."</td>";
echo "<td>".$row['nama_tahun']."</td>";
echo "<td>".$row['nama_turunan_tahun']."</td>";
echo "<td>".$row['data_content']."</td>";
echo "<td>".$row['nama_item_vertical_variabel']."</td>";
echo "</tr>";
}
echo "</tbody></table></table>";
}
} else {
echo "0 results";
}
?>
最佳答案
你需要在while循环之前写上tbody。
关于javascript - mysql 的输出不会在表上正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50445388/