2015-12-29 15 views
1

使用PDO和表顯示它從數據庫中有表讀數值,於是最後我code.Now具有分頁我的表,搜索選項一起使用的DataTable的JavaScript IM。 但現在我想包括一個更多的列作爲'行動'做編輯,刪除fucntion.When我包括這些第五列作爲行動。然後我的表顯示爲正常..而不是數據表格格式(分頁,搜索選項不存在)。我下面的編碼:增加列數未能在PHP數據表

<?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> 

回答

1

您的表頭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 } 
+0

是的,以前我有​​,無需添加 .Same錯誤。所以我刪除​​並添加和​​同樣的事情發生。但現在我改變了,它的工作。謝謝。 – Anu