2015-06-25 27 views
-1

目前我有一个显示在单个页面上系统上的所有订单页面,这部分工作正常,是没有问题的。当我们达到一定量的订单我想让它易于消化,所以最大的订单,将显示在页面上立刻将是15和数据将被排序更快的搜索,就会出现问题。我怎样才能使数据排序按日期在SQL填充表?

我的代码如下:

<?php 
          $servername = "localhost"; 
          $username = "qwe"; 
          $password = "qwe"; 
          $dbname = "qwe"; 

          // Create connection 
           $conn = new mysqli($servername, $username, $password, $dbname); 
          // Check connection 
          if ($conn->connect_error) { 
           die("Connection failed: " . $conn->connect_error); 
          } 

          $sql = "SELECT * FROM Orders ORDER BY ID DESC";       
          $result = $conn->query($sql); 

          if ($result->num_rows > 0) { 
           echo "<table class='table table-hover' id='orders'><tr style='font-size:18px;'><th style='text-align:center;'>ID</th><th style='text-align:center;'>Customer</th><th style='text-align:center;'>Material</th><th style='text-align:center;'>Quantity</th><th style='text-align:center;'>Delivery</th><th style='text-align:center;'>Post Code</th><th style='text-align:center;'>Cost/Tonne</th><th style='text-align:center;'>Total</th><th style='text-align:center;'>Paid</th><th style='text-align:center;'>Staff</th><th style='text-align:center;'>Timestamp</th></tr>"; 
           // output data of each row 
           while($row = $result->fetch_assoc()) { 
            echo "<tr style='font-size:16px; text-align:center;'><td><span style='color:#0b78e5;'>SGL</span><a href='#' style='color:#0b78e5;'>".$row["ID"]."</a></td><td>".$row["Customername"]."</td><td>".$row["Material"]."</td><td>".$row["Quantity"]."</td><td><input type='checkbox' disabled". ($row["Delivery"] == 'Yes' ? " checked" : "") ."></td><td>".$row["Postcode"]."</td><td>&pound;".$row["CostPerTonne"]."</td><td>&pound;".$row["TotalCost"]."</td><td>".$row["Paid"]."</td><td>".$row["Username"]."</td><td>".$row["Logged"]."</td></tr>"; 
           } 
           echo "</table>"; 
          } else { 
           echo "There are 0 orders in the system"; 
          } 
          $conn->close(); 
         ?> 

我的问题是使用我已经有数据存在使表按日期排序的方法吗?

+0

搜索看起来像你需要分页。在堆栈溢出时搜索相同的内容 – Madhivanan

回答

0

按日期排序,你必须创建提供时间戳数据类型的列,并保留默认值CURRENT_TIMESTAMP,或猜测的订单更大的id是最新的,你当前的代码会按日期排序。您可以通过所有列使用的DataTable https://www.datatables.net/,数据表提供了相反的顺序排序,并为使您搜索的项目更容易

相关问题