简体   繁体   English

搜索,分页和排序在数据表中不起作用

[英]Search, pagination and sorting not working in datatable

Currently, I am working on my datatable to display the detail from the database. 当前,我正在数据表上显示数据库的详细信息。 I am using the php myadmin for the database. 我正在使用php myadmin作为数据库。 But it only manage to display the detail only but not the pagination, sorting and searching is not working. 但是它只能显示详细信息,而不能显示分页,排序和搜索不起作用。 I have followed some other tutorials but it still doesn't work. 我遵循了其他一些教程,但仍然无法正常工作。

<?php  
$conn = mysqli_connect("localhost", "root", "", "jiaen"); 
$sql = "SELECT * FROM stock LEFT OUTER JOIN category ON stock.categoryid=category.categoryid order by stockCode";

//Execute connection
$result = mysqli_query($conn,$sql); 
?>  
<!DOCTYPE html>  
<html>  
<head>  
   <title>Webslesson Tutorial | Datatables Jquery Plugin with Php MySql and Bootstrap</title>  
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
   <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>  
   <script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>            
   <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />  
   </script>
</head>  
<body>  
  <br /><br />  
  <div class="container">  
      <h3 align="center">Datatables Jquery Plugin with Php MySql and Bootstrap</h3>  
      <br />  
      <div class="table-responsive">  
           <table id="stock" class="table table-striped table-bordered" > 
              <thead>  
                 <tr>  
                    <td>Stock Code</td>  
                    <td>Stock Name</td> 
                     <td>Stock Category</td>  
                    <td>Quantity</td>  
                    <td>Price (RM)</td>  
                    <td>Action</td>  
                 </tr>  
              </thead> 
              <tbody>  
              <?php  
              while($row = mysqli_fetch_array($result))  
              {  
                 echo '  

                 <tr>  
                    <td>'.$row["stockCode"].'</td>  
                    <td>'.$row["stockName"].'</td>  
                    <td>'.$row["categoryName"].'</td>  
                    <td>'.$row["quantity"].'</td>  
                    <td>'.$row["price"].'</td>
                    <td><a href = "add.php?id='.$row["stockCode"].'">Stock In</a></td> 
                    <td><a href = "rnd.php?id='.$row["stockCode"].'">R&D</a></td> 
                    <td><a href = "remarkstock.php?id='.$row["stockCode"].'">Remark Stock</a></td> 
                    <td><a href = "modify.php?id='.$row["stockCode"].'">Modify</a></td> 
                    <td><a href = "delete.php?id='.$row["stockCode"].'">Delete</a></td>   
                 </tr> 

                 ';  
              }  
              ?>  
              </tbody> 
           </table>  

      </div>  
  </div> 

  //Javascript part for datatable  
  <script>  
  $(document).ready(function() {
      $('#stock').DataTable();
  } );
  </script>
</body>  
</html>  

Your <thead> contains a <tr> which is full of <td> tags instead of <th> tags. 您的<thead>包含一个<tr> ,其中充满了<td>标签而不是<th>标签。

It has 6 tags, so your table will have 6 columns. 它具有6个标签,因此您的表将具有6列。

Your <tbody> on the other hand has 10 <td> tags inside each <tr> tag. 另一方面,您的<tbody>在每个<tr>标记内有10个<td> <tr>标记。

10 will not fit into 6. 10不能容纳6。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM