Tweet
                              
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 :Name Number Quantity DVD 1 10 PENDRIVE 2 50 CD 3 25 KEYBOARD 4 15 
After executing the program :Name Number Quantity CD 3 25 DVD 1 10 KEYBOARD 4 15 PENDRIVE 2 50 
This post is about sorting data in the mysql database using php.
 
 

 



 
 
 
 
