Sort the data in a recordset with ORDER BY keyword in PHP

Description

The following code shows how to sort the data in a recordset with ORDER BY keyword.

Example


//  ww  w.j  ava2 s  . c  o  m
<?php
    $con=mysqli_connect("example.com","root","","test");
    // Check connection
    if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $result = mysqli_query($con,"SELECT * FROM employee ORDER BY name");

    while($row = mysqli_fetch_array($result)) {
      echo $row['ID'];
      echo " " . $row['Name'];
      echo " " . $row['Birthday'];
      echo "<br>";
    }

    mysqli_close($con);
?>




















Home »
  PHP Tutorial »
    MySQL »




MySQLi
MySQLi Object Oriented