【发布时间】:2015-09-11 20:16:48
【问题描述】:
目前我有一个页面在一个页面上显示系统上的所有订单,这部分工作正常,不是问题。当我们达到一定数量的订单时会出现问题,我想让它易于消化,因此一次在页面上显示的最大订单数为 15,并且数据可以排序以加快搜索速度。
我的代码如下:
<?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>£".$row["CostPerTonne"]."</td><td>£".$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();
?>
我的问题是使用我已有的数据,有什么方法可以让表格按日期排序?
【问题讨论】:
-
看起来你需要分页。在堆栈溢出中搜索相同的内容
标签: php jquery mysql sql html-table