//create the database with name "weblab" //create the table name student // usn,name,marks query($sql); $usn = array() ; echo "
"; echo ""; if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo ""; echo ""; echo ""; $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 "
Before Sorting
USNNAMEMarks
". $row["usn"]."". $row["name"]."". $row["marks"]."

"; echo ""; for($i = 0 ; $i < sizeof($usn) ; $i++) { echo ""; echo ""; echo ""; } ?>
After Sorting
USNNAMEMarks
". $usn[$i]."". $name[$i]."". $marks[$i]."