php - How can I make data sortable by date in an SQL populated table? -


currently have page displays orders on system on single page, part working fine , not problem. issue occurs when reach amount of orders want make easy digest, max orders show on page @ once 15 , data sortable faster searching.

my code below:

<?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 * orders order 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 0 orders in system";                             }                             $conn->close();                         ?> 

my question using data have there way of making table sortable date?

to sort date , have create column timestamp data type , keep default value current_timestamp , or guessing orders larger id latest , current code sorted date. can use datatables https://www.datatables.net/ , data tables provide sorting in reverse order columns , search making search item easier


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -