Sort Column (Ascending and Descending) in PHP/MySQL

Language

Hi guys, In this source code you will learn on how to make a query in MySQL that enables you to sort data by ascending and descending order. This code is simple yet useful to some beginners who want to learn about PHP and MySQL hope you will like this code Thank you. Database name: asc_desc.sql in db folder. Sample code:
  1. <?php include('header.php'); ?>
  2. <html>
  3. <body>
  4. <div class="row-fluid">
  5. <div class="span12">
  6. <div class="container"> <br>
  7. <br>
  8. <label>Order by:</label>
  9. <a class="btn" href="ascending.php">Ascending</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a class="btn" href="decending.php">Decending</a> <br>
  10. <br>
  11. <table class="table table-striped table-bordered">
  12. <thead>
  13. <tr>
  14. <th>FirstName</th>
  15. <th>LastName</th>
  16. <th>MiddleName</th>
  17. <th>Address</th>
  18. <th>Email</th>
  19. </tr>
  20. </thead>
  21. <tbody>
  22. <?php
  23. $query=mysql_query("select * from member")or die(mysql_error());
  24. while($row=mysql_fetch_array($query)){
  25. $id=$row['member_id'];
  26. ?>
  27. <tr>
  28. <td><?php echo $row['firstname'] ?></td>
  29. <td><?php echo $row['lastname'] ?></td>
  30. <td><?php echo $row['middlename'] ?></td>
  31. <td><?php echo $row['address'] ?></td>
  32. <td><?php echo $row['email'] ?></td>
  33. </tr>
  34. <?php } ?>
  35. </tbody>
  36. </table>
  37. </form>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. </body>
  43. </html>

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Add new comment