-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp10.php
More file actions
31 lines (31 loc) · 784 Bytes
/
p10.php
File metadata and controls
31 lines (31 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
header('Content-Type: text/plain');
$usn=array();
$name= array();
$conn = new mysqli("localhost","root","","weblab");
$query = "SELECT * FROM student";
$res =mysqli_query($conn,$query);
echo "Before sorting \n";
while($row = mysqli_fetch_assoc($res)){
echo $row["usn"]."\t".$row["name"]."\n";
array_push($usn,$row["usn"]);
$name[$row["usn"]] = $row["name"];
}
$count=count($usn);
for ( $i = 0 ; $i < $count ; $i++ ){
$pos= $i;
for ( $j = $i + 1 ; $j < $count ; $j++ ) {
if ( $usn[$j] < $usn[$pos] )
{
$pos= $j;
}
}
$temp = $usn[$i];
$usn[$i] = $usn[$pos];
$usn[$pos] = $temp;
}
echo "After sorting\n";
foreach( $usn as $u ){
echo $u."\t".$name[$u]."\n";
}
?>