Below is my code
<?php
session_start();
function cmp ($a,$b) {
return strcmp($a[0],$b[0]);}
$x=0;
$query ="select field1,field2,field3,field4 from mysqltable";
$result=mysql_query($query, $link);
while($myrow=mysql_fetch_row($result)) {
$arr[$x][0]=$myrow[0];
$arr[$x][1]=$myrow[1]; // I want to sort based on this column
$arr[$x][2]=$myrow[2];
$arr[$x][3]=$myrow[3];
$x++;}
usort($arr,"cmp");
echo "<table>";
for ($x=0;$x<count($arr);$x++) {
echo "<tr><td>".$arr[$x][2]."</td>";
echo "<td>".$arr[$x][1]."</td>";
echo "<td>".$arr[$x][3]."</td>";
echo "<td>".$arr[$x][4]."</td>";
echo "<td>".$arr[$x][0]."</td></tr>";
}
echo "</table>";
echo "</body></html>";
?>