忽略引导表设计的 PHP 文件

标签 php mysql html-table bootstrap-4

我正在尝试使用以下代码从数据库中检索数据并将其显示在 PHP 文件中:

index.php

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">


    <title>Control Panel</title>
    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="css/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <link href="css/nprogress.css" rel="stylesheet">
    <!-- iCheck -->
    <link href="css/green.css" rel="stylesheet">
    <!-- Datatables -->
    <link href="css/dataTables.bootstrap.min.css" rel="stylesheet">
    <link href="css/buttons.bootstrap.min.css" rel="stylesheet">
    <link href="css/fixedHeader.bootstrap.min.css" rel="stylesheet">
    <link href="css/responsive.bootstrap.min.css" rel="stylesheet">
    <link href="css/scroller.bootstrap.min.css" rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="css/custom.min.css" rel="stylesheet">
  </head>

  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-12 left_col">
          <div class="left_col scroll-view">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_content">
                    <?php
                    $count_rows = 0;
                    include 'database_connection.php';
                    $sql = "SELECT date, ip, activate FROM software";
                    $result = $conn->query($sql);
                    echo "<table id='datatable-buttons class='table table-striped table-bordered'>
                          <tr>
                          <th>S/N</th>
                          <th>Date</th>
                          <th>IP Address</th>
                          <th>Activation</th>
                          </tr>";
                    while ($row = mysqli_fetch_array($result)) {
                    $count_rows++;
                    echo "<tr>";
                    echo "<td>" . $count_rows . "</td>";
                    echo "<td>" . $row['date'] . "</td>";
                    echo "<td>" . $row['ip'] . "</td>";
                    echo "<td>" . $row['activate'] . "</td>";
                    echo "</tr>";
                    }
                    mysqli_close($conn);
                    ?>
    <!-- jQuery -->
    <script src="js/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="js/fastclick.js"></script>
    <!-- NProgress -->
    <script src="js/nprogress.js"></script>
    <!-- iCheck -->
    <script src="js/icheck.min.js"></script>
    <!-- Datatables -->
    <script src="js/jquery.dataTables.min.js"></script>
    <script src="js/dataTables.bootstrap.min.js"></script>
    <script src="js/dataTables.buttons.min.js"></script>
    <script src="js/buttons.bootstrap.min.js"></script>
    <script src="js/buttons.flash.min.js"></script>
    <script src="js/buttons.html5.min.js"></script>
    <script src="js/buttons.print.min.js"></script>
    <script src="js/dataTables.fixedHeader.min.js"></script>
    <script src="js/dataTables.keyTable.min.js"></script>
    <script src="js/dataTables.responsive.min.js"></script>
    <script src="js/responsive.bootstrap.js"></script>
    <script src="js/dataTables.scroller.min.js"></script>
    <script src="js/jszip.min.js"></script>
    <script src="js/pdfmake.min.js"></script>
    <script src="js/vfs_fonts.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="js/custom.min.js"></script>

  </body>
</html>

我得到了结果,但格式不正确。使用几乎相同的代码,我可以获得设计但无法获得数据:这是有效但未显示数据的代码。

index.html(不完整的代码)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Control Panel</title>
    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="css/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <link href="css/nprogress.css" rel="stylesheet">
    <!-- iCheck -->
    <link href="css/green.css" rel="stylesheet">
    <!-- Datatables -->
    <link href="css/dataTables.bootstrap.min.css" rel="stylesheet">
    <link href="css/buttons.bootstrap.min.css" rel="stylesheet">
    <link href="css/fixedHeader.bootstrap.min.css" rel="stylesheet">
    <link href="css/responsive.bootstrap.min.css" rel="stylesheet">
    <link href="css/scroller.bootstrap.min.css" rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="css/custom.min.css" rel="stylesheet">
  </head>

  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-12 left_col">
          <div class="left_col scroll-view">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_content">
                    <table id="datatable-buttons" class="table table-striped table-bordered">
                      <thead>
                        <tr>
                          <th>S/N</th>
                          <th>Date</th>
                          <th>IP Address</th>
                          <th>Activation</th>
                        </tr>
                      </thead>
                    <tbody>
                    <tr>;
                    <td> $row['id'] </td>
                    <td> $row['date'] </td>
                    <td> $row['ip'] </td>
                    <td> $row['activate'] </td>
                    </tr>
                     </tbody>
                    </table>
                  </div>
                </div>
              </div>

    <!-- jQuery -->
    <script src="js/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="js/fastclick.js"></script>
    <!-- NProgress -->
    <script src="js/nprogress.js"></script>
    <!-- iCheck -->
    <script src="js/icheck.min.js"></script>
    <!-- Datatables -->
    <script src="js/jquery.dataTables.min.js"></script>
    <script src="js/dataTables.bootstrap.min.js"></script>
    <script src="js/dataTables.buttons.min.js"></script>
    <script src="js/buttons.bootstrap.min.js"></script>
    <script src="js/buttons.flash.min.js"></script>
    <script src="js/buttons.html5.min.js"></script>
    <script src="js/buttons.print.min.js"></script>
    <script src="js/dataTables.fixedHeader.min.js"></script>
    <script src="js/dataTables.keyTable.min.js"></script>
    <script src="js/dataTables.responsive.min.js"></script>
    <script src="js/responsive.bootstrap.js"></script>
    <script src="js/dataTables.scroller.min.js"></script>
    <script src="js/jszip.min.js"></script>
    <script src="js/pdfmake.min.js"></script>
    <script src="js/vfs_fonts.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="js/custom.min.js"></script>

  </body>
</html>

我当然知道 index.html 代码不正确或不完整。然而,它确实完美地加载了引导表设计。我在 PHP 文件上做什么?

请在这里指导我。

index.php 截图:http://oi65.tinypic.com/z7ed3.jpg

index.html 截图:http://oi68.tinypic.com/2zqqvc6.jpg

最佳答案

请更改 index.php 文件中的代码:

<table id='datatable-buttons class='table table-striped table-bordered'>

<table id='datatable-buttons' class='table table-striped table-bordered'>

您没有在 id datatable-buttons 后关闭报价 并添加 </table> while结束后 block

在您的情况下,您可以将代码更改为以下代码:

<table id="datatable-buttons" class="table table-striped table-bordered">
    <thead>
    <tr>
        <th>S/N</th>
        <th>Date</th>
        <th>IP Address</th>
        <th>Activation</th>
    </tr>
    </thead>        
    <tbody>

    <?php
    $count_rows = 0;
    include 'database_connection.php';
    $sql = "SELECT `date`, `ip`, `activate` FROM `software`";
    $result = $conn->query($sql);

    while ($row = mysqli_fetch_array($result)):
        $count_rows++;
        ?>
        <tr>
            <td><?php echo $count_rows ?></td>
            <td><?php echo $row['id']; ?></td>
            <td><?php echo $row['date']; ?></td>
            <td><?php echo $row['ip']; ?></td>
            <td><?php echo $row['activate']; ?></td>
        </tr>
    <?php endwhile; ?>
    </tbody>
</table>

关于忽略引导表设计的 PHP 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51865815/

相关文章:

html - LI 元素内的奇怪 TABLE 边距行为

php - 这两种 MySQL 连接方法有什么区别

php - 终端和工作台中的Mysql看不到相同的数据库

javascript - 从我的网页发送电子邮件时出错

mysql - Azure MySql + Sequelize 之间的连接

html - 样式 :Display and Visibility errors?

php - 将类似日期的字符串保存到数据库,但 MYSQL 将其转换为十进制字符串

mysql - 覆盖gorm中的外键和引用

MySQL 子查询使用 NULLIF 截断结果

php - 无法显示 mysql wpdb 表,其中包含有关 woocommerce 产品的信息,但没有包含已删除产品的行;也无法对 html 表进行分页