PHP/MySQL 使用 bootstrap 输出到表中 - 列困惑

标签 php mysql twitter-bootstrap

我在 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/

相关文章:

php - 不同模型类型 Laravel 上的不同关系

php - 从两个以上的表中获取数据时,我应该一直使用 LEFT JOIN 吗?

php - 访问结果集行中的值,其中该值来自 MySQL 函数调用

html - Bootstrap 行超过 Container-Fluid

jquery - RequireJS 无法与 Shim'ed jQuery 插件一起使用

php - 上传数据到服务器后出现404错误

php - Laravel 5 文件删除错误

html - 在 bootstrap 容器中将 2 个绝对 DIV 放置在 1 个相对 DIV 中

php - 设置结果并在一个 if 中检查行数

mysql - 绘制 MySQL 数据图形的程序