我在 mysql 输出到表中时遇到问题。脚本运行完美,我得到了我需要的数据,但表中的列很困惑。这些多重 echo 似乎可能存在问题,但我尝试了我发现/想到的所有可能的组合,但到目前为止没有任何效果。
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo"<table class='table table-hover table-striped table-responsive'>";
echo"<tr class='table_row'>";
echo"<td>" . $row['1'] . "</td>";
echo"<td>" . $row['2'] . "</td>";
echo"<td>" . $row['3'] . "</td>";
echo"<td>" . $row['4'] . "</td>";
echo"<td><a href='#'><button type='button' class='btn btn-danger btn-xs glyphicon glyphicon-remove-circle'></button></a></td>";
echo"</tr>";
echo"</table>";
}
}
最佳答案
你必须尝试这个:
if (mysqli_num_rows($result) > 0) {
echo"<table class='table table-hover table-striped table-responsive'>";
while($row = mysqli_fetch_assoc($result)) {
echo"<tr class='table_row'>";
echo"<td>" . $row['1'] . "</td>";
echo"<td>" . $row['2'] . "</td>";
echo"<td>" . $row['3'] . "</td>";
echo"<td>" . $row['4'] . "</td>";
echo"<td><a href='#'><button type='button' class='btn btn-danger btn-xs glyphicon glyphicon-remove-circle'></button></a></td>";
echo"</tr>";
}
echo"</table>";
}
您正在 while 循环内重复该表。希望这对您有帮助。
关于PHP/MySQL 使用 bootstrap 输出到表中 - 列困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32169838/