Sort data in the mysql database using php

This post is about sorting data in the mysql database using php.

The php code :

<?php
$connection=mysql_connect("localhost","root","")
   or die("Couldn't connect to the server");
$db=mysql_select_db("produce",$connection)
   or die ("Couldn't select database");
$result=mysql_query("SELECT * FROM fruit ORDER BY name"); 
echo "<table border='1'>";
echo "<tr>";
echo "<th>Name</th><th>Number</th><th>Quantity</th>";
echo "</tr>";
while($row=mysql_fetch_array($result))
{
     echo "<tr>";
     echo "<td>",$row['name'],"</td><td>",$row['number'],"  

    </td><td>",$row['quantity'],"</td>";
    echo "</tr>";
}
echo "</table>";
mysql_close($connection);
?>   


Before executing the program :
NameNumberQuantity
DVD110
PENDRIVE250
CD325
KEYBOARD415
          
After executing the program :
NameNumberQuantity
CD325
DVD110
KEYBOARD415
PENDRIVE250
        

Top