dongting3135 2018-11-08 14:38
浏览 78
已采纳

DataTables无法应用于表

I'm trying to use DataTables but for some reason, it doesn't seem to be working. I'm using Bootstrap 4 and I need buttons from DataTables so that I can export the table later. I think I've added everything I need but it's not showing up. anyone know why it hasn't worked? The table is being posted from a database, it works just fine in bootstrap and all the information shows up but as soon as I try to add DataTables to it nothing seems to change.

 <?php 
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);

    include_once('connection.php');
    if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['someAction']))
        {
            func();
        }
        function func()
        {
          $conn = mysqli_connect("localhost", "root", "", "SportsDB");
        }
    session_start();
    if( !isset($_SESSION['username']) ){ /* Change into role = teacher or admin*/
      header('Location:login.php');
    }

    print_r($_SESSION);
    ?>

    <!DOCTYPE html>
    <html lang='en'>
    <head>
      <meta charset="UTF-8">
      <title>Register exporting</title>
      <!--- Link to Bootstrap 4 -->
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
      <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
      <!-- Link to Data Tables -->
      <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/jszip-2.5.0/dt-1.10.18/b-1.5.4/b-flash-1.5.4/b-html5-1.5.4/datatables.min.css"/>

      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
      <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
      <script type="text/javascript" src="https://cdn.datatables.net/v/bs4/jszip-2.5.0/dt-1.10.18/b-1.5.4/b-flash-1.5.4/b-html5-1.5.4/datatables.min.js"></script>

      <!-- Link to jquery -->
      <script
      src="http://code.jquery.com/jquery-3.3.1.min.js"
      integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
      crossorigin="anonymous"></script>

    </head>
    <body>
      <div class='container-fluid' style='margin-top: 20px'>
        <div class="row">
          <div class="col-md-8 mx-auto">
            <table class="table table-bordered table-hover" id='example'>
              <thead>
                <tr>
                  <td>ID</td>
                  <td>Username</td>
                  <td>T1_choice</td>
                  <td>T2_choice</td>
                  <td>T3_choice</td>
                </tr>
              </thead>
              <tfoot>
                <tr>
                  <td>ID</td>
                  <td>Username</td>
                  <td>T1_choice</td>
                  <td>T2_choice</td>
                  <td>T3_choice</td>
                </tr>
              </tfoot>
              <tbody>
                <?php
                  ini_set("display_errors", 1);
                  $stmt = $conn->query('SELECT * FROM Student_Choices');
                  while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                    echo '<tr>
                        <td>'.$row['Unique_ID'].'</td>
                        <td>'.$row['Username'].'</td>
                        <td>'.$row['T1_Choice'].'</td>
                        <td>'.$row['T2_Choice'].'</td>
                        <td>'.$row['T3_Choice'].'</td>
                      </tr>
                    ';
                  }
                ?>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    <script type="text/javascript">
      $(document).ready(function() {
        $('#example').DataTable();
      } );
    </script>
    </body>
    </html>
  • 写回答

1条回答 默认 最新

  • duandi5328 2018-11-08 15:04
    关注

    Thanks for the help. I needed to call the jquery before DataTables.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于温度改变石墨烯介电性能(关键词-介电常数)
  • ¥150 HDMI分路器LT86102 的输出在890MHz频点处EMC超标8DB
  • ¥15 druid(相关搜索:数据库|防火墙)
  • ¥15 大一python作业
  • ¥15 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
  • ¥60 如何鉴定微信小程序数据被篡改过
  • ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
  • ¥20 C#上传XML格式数据
  • ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下
  • ¥20 手机截图相片分辨率降低一半