//create the database with name "weblab"
//create the table name student
// usn,name,marks
query($sql);
$usn = array() ;
echo "
Before Sorting
";
echo "| USN | NAME | Marks |
";
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
echo "| ". $row["usn"]." | ";
echo "". $row["name"]." | ";
echo "". $row["marks"]." |
";
$usn[] = $row["usn"] ;
}
}
$n = sizeof($usn) ;
for($i = 0 ; $i < $n-1 ; $i++ )
{
$pos = $i ;
for($j = $i + 1 ; $j < $n ; $j++ )
{
if( $usn[$pos] < $usn[$j])
{
$pos = $j ;
}
}
if( $pos != $i)
{
$temp = $usn[$i] ;
$usn[$i] = $usn[$pos] ;
$usn[$pos] = $temp ;
}
}
$name = [] ;
$marks = [] ;
$result = $conn->query($sql);
if ($result->num_rows> 0)
{
while($row = $result->fetch_assoc())
{
for($i=0;$i<$n;$i++)
{
if($row["usn"] == $usn[$i])
{
$name[$i]=$row["name"];
$marks[$i]=$row["marks"];
}
}
}
}
echo "
After Sorting
";
echo "| USN | NAME | Marks |
";
for($i = 0 ; $i < sizeof($usn) ; $i++)
{
echo "| ". $usn[$i]." | ";
echo "". $name[$i]." | ";
echo "". $marks[$i]." |
";
}
?>