-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoftUni-Students.php
56 lines (42 loc) · 1.34 KB
/
SoftUni-Students.php
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
$students=$_GET['students'];
$column=$_GET['column'];
$order=$_GET['order'];
$arrayRows=preg_split("/\n/", $students, -1, PREG_SPLIT_NO_EMPTY);
$data=Array();
$i=0;
foreach($arrayRows as $key => $value){
$data[$i]=preg_split("/,/", $value, -1, PREG_SPLIT_NO_EMPTY);
$i++;
}
for($s=0;$s<$i;$s++){
array_unshift($data[$s],$s+1);
}
//print_r($data);
// Obtain a list of columns
foreach ($data as $key => $row) {
$id[$key] = $row[0];
$username[$key] =trim($row[1]);
$email[$key] =trim($row[2]);
$type[$key] = trim($row[3]);
$result[$key]=(int)trim($row[4]);
}
// Sort the data with volume descending, edition ascending
// Add $data as the last parameter, to sort by the common key
if($order=="ascending"){
array_multisort(${$column}, SORT_ASC, $id, SORT_ASC, $data);
}
elseif($order=="descending"){
array_multisort(${$column}, SORT_DESC, $id, SORT_DESC, $data);
}
echo '<table><thead><tr><th>Id</th><th>Username</th><th>Email</th><th>Type</th><th>Result</th></tr></thead>';
foreach($data as $key =>$value){
echo '<tr>';
echo '<td>'.htmlspecialchars(trim($value[0])).'</td>';
echo '<td>'.htmlspecialchars(trim($value[1])).'</td>';
echo '<td>'.htmlspecialchars(trim($value[2])).'</td>';
echo '<td>'.htmlspecialchars(trim($value[3])).'</td>';
echo '<td>'.htmlspecialchars(trim($value[4])).'</td>';
echo '</tr>';
}
echo '</table>';