Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. <?php
  2.  
  3. $input = preg_split("/\n/", $_GET['students']);
  4. $column = $_GET['column'];
  5. $order = $_GET['order'];
  6. unset($input[count($input) - 1]);
  7. for ($i = 0; $i < count($input); $i ++) {
  8. $input[$i] = preg_split('/, /', $input[$i]);
  9. $input[$i][] = $i + 1;
  10. }
  11. if($column == 'result'){
  12. $column = 3;
  13. } else if($column == 'id'){
  14. $column = 4;
  15. }
  16. else $column = 0;
  17.  
  18. if($column == 0){
  19. if($order == 'descending'){
  20. uasort($input , 'dComparerUsername');
  21. }
  22. else{
  23. uasort($input, 'ComparerUsername');
  24. }
  25. }
  26. else if($column == 3){
  27. if($order == 'descending'){
  28. uasort($input , 'dComparerResult');
  29. }
  30. else{
  31. uasort($input, 'ComparerResult');
  32. }
  33. }
  34. else{
  35.  
  36. if($order == 'descending'){
  37. uasort($input , 'dComparerid');
  38. }
  39. else{
  40. uasort($input, 'Comparerid');
  41. }
  42.  
  43. }
  44.  
  45. echo '<table><thead><tr><th>Id</th><th>Username</th><th>Email</th><th>Type</th><th>Result</th></tr></thead>';
  46.  
  47. foreach ($input as $key => $value) {
  48. echo '<tr><td>' . htmlspecialchars(trim($input[$key][4])) . '</td><td>' . htmlspecialchars(trim($input[$key][0])) . '</td><td>' . htmlspecialchars(trim($input[$key][1])) . '</td><td>' . htmlspecialchars(trim($input[$key][2])) . '</td><td>' . htmlspecialchars(trim($input[$key][3])) . '</td></tr>';
  49. }
  50.  
  51. echo '</table>';
  52.  
  53.  
  54.  
  55.  
  56. function dComparerResult($first, $second) {
  57.  
  58. if ((int)$first[3] < (int)$second[3]) {
  59. return 1;
  60. }
  61. else if ((int)$first[3] > (int)$second[3]) {
  62. return -1;
  63. }
  64.  
  65.  
  66. if ((int)$first[4] < (int)$second[4]) {
  67. return 1;
  68. }
  69. else if ((int)$first[4] > (int)$second[4]) {
  70. return -1;
  71. }
  72. return 0;
  73. }
  74.  
  75.  
  76. function ComparerResult($first, $second) {
  77.  
  78. if ((int)$first[3] < (int)$second[3]) {
  79. return -1;
  80. }
  81. else if ((int)$first[3] > (int)$second[3]) {
  82. return 1;
  83. }
  84.  
  85.  
  86. if ((int)$first[4] < (int)$second[4]) {
  87. return -1;
  88. }
  89. else if ((int)$first[4] > (int)$second[4]) {
  90. return 1;
  91. }
  92. return 0;
  93. }
  94.  
  95.  
  96. function dComparerid($first, $second) {
  97.  
  98. if ((int)$first[4] < (int)$second[4]) {
  99. return 1;
  100. }
  101. else if ((int)$first[4] > (int)$second[4]) {
  102. return -1;
  103. }
  104. return 0;
  105. }
  106.  
  107. function Comparerid($first, $second) {
  108.  
  109. if ((int)$first[4] < (int)$second[4]) {
  110. return -1;
  111. }
  112. else if ((int)$first[4] > (int)$second[4]) {
  113. return 1;
  114. }
  115. return 0;
  116. }
  117.  
  118.  
  119.  
  120. function dComparerUsername($first, $second) {
  121.  
  122. if ($first[3] < $second[3]) {
  123. return 1;
  124. }
  125. else if ($first[3] > $second[3]) {
  126. return -1;
  127. }
  128.  
  129.  
  130. if ((int)$first[4] < (int)$second[4]) {
  131. return 1;
  132. }
  133. else if ((int)$first[4] > (int)$second[4]) {
  134. return -1;
  135. }
  136. return 0;
  137. }
  138.  
  139.  
  140. function ComparerUsername($first, $second) {
  141.  
  142. if ($first[3] < $second[3]) {
  143. return -1;
  144. }
  145. else if ($first[3] > $second[3]) {
  146. return 1;
  147. }
  148.  
  149.  
  150. if ((int)$first[4] < (int)$second[4]) {
  151. return -1;
  152. }
  153. else if ((int)$first[4] > (int)$second[4]) {
  154. return 1;
  155. }
  156. return 0;
  157. }
  158. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement