php中失败数据表的列数不断增加


Increasing number of columns fails datatable in php

im让表使用PDO从数据库中读取值并将其显示在表中,然后最后使用Datatable javascript代码。现在我的表有分页,搜索选项。但现在我想再包含一列作为"操作"来进行编辑、删除功能。当我把这第五栏列为"行动"时。然后我的桌子就正常了。。不是数据表格式(分页,搜索选项不存在)。我在下面的编码:

<?php
include("config.php");
include("header.php");
try {
    $sql = "SELECT * FROM auditplan";
    $stmt = $DB->prepare($sql);
    $stmt->execute();
    $result = $stmt->fetchAll();
} catch (Exception $ex) {
    echo $ex->getMessage();
}
?>
<link rel="stylesheet" href="<?=BASE_URL?>/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="<?=BASE_URL?>/bootstrap/css/bootstrap.min.css">
<script type="text/javascript" src="<?=BASE_URL?>js/jquery2.0.2.min.js"></script>
<script type="text/javascript" src="<?=BASE_URL?>js/jquery.dataTables.js"></script>
<script type="text/javascript" src="<?=BASE_URL?>js/jquery.dataTables.min.js"></script>
<link href="<?=BASE_URL?>themecss/datatables/dataTables.bootstrap.css" rel="stylesheet">
<script src="<?=BASE_URL?>themejs/plugins/datatables/dataTables.bootstrap.js"></script>
<script src="<?=BASE_URL?>themejs/jquery-ui-1.10.3.js"></script>
<script src="<?=BASE_URL?>themejs/jquery-ui-1.10.3.min.js"></script>
<div class="col-sm-9 col-md-10 main">
   <h1 class="page-header"> Audit Plan </h1>
   <a href="Auditplanentry.php" class="btn btn-primary" >Add New</a>
   <table class="table table-striped"  id="auditplantbl">
      <thead>
         <tr>
            <th>Audit ID</th>
            <th>Year</th>
            <th>Month</th>
            <th>Status</th>
            <th>Comments</th>
            <th>Action</th>
         </tr>
      </thead>
      <tbody>
         <?php
          foreach($result as $row){ ?>
         <tr>
            <td><?php echo $row['auditid']?></td>
            <td><?php echo $row['year'] ?></td>
            <td><?php echo $row['month'] ?></td>
            <td><?php echo $row['status']?></td>
            <td><?php echo $row['comment']?></td>
         </tr>
         <?php  }
        ?>
      </tbody>
   </table>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('#auditplantbl').dataTable({
            "bLengthChange": false,
        });
    });
</script>

您的表头中有6列,但表体中只有5列,您需要在表头和表体中匹配相同数量的列才能使数据表正常工作。

你需要在正文中添加一个来添加按钮,或者你计划做的任何事情来删除或编辑你的项目:

<?php
foreach($result as $row){ ?>
    <tr>
      <td><?php echo $row['auditid']?></td>
      <td><?php echo $row['year'] ?></td>
      <td><?php echo $row['month'] ?></td>
      <td><?php echo $row['status']?></td>
      <td><?php echo $row['comment']?></td>          
      <td> edit link / delete link </td>
      </tr>
<?php  }