Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = preg_split("/\n/", $_GET['students']);
- $column = $_GET['column'];
- $order = $_GET['order'];
- unset($input[count($input) - 1]);
- for ($i = 0; $i < count($input); $i ++) {
- $input[$i] = preg_split('/, /', $input[$i]);
- $input[$i][] = $i + 1;
- }
- if($column == 'result'){
- $column = 3;
- } else if($column == 'id'){
- $column = 4;
- }
- else $column = 0;
- if($column == 0){
- if($order == 'descending'){
- uasort($input , 'dComparerUsername');
- }
- else{
- uasort($input, 'ComparerUsername');
- }
- }
- else if($column == 3){
- if($order == 'descending'){
- uasort($input , 'dComparerResult');
- }
- else{
- uasort($input, 'ComparerResult');
- }
- }
- else{
- if($order == 'descending'){
- uasort($input , 'dComparerid');
- }
- else{
- uasort($input, 'Comparerid');
- }
- }
- echo '<table><thead><tr><th>Id</th><th>Username</th><th>Email</th><th>Type</th><th>Result</th></tr></thead>';
- foreach ($input as $key => $value) {
- 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>';
- }
- echo '</table>';
- function dComparerResult($first, $second) {
- if ((int)$first[3] < (int)$second[3]) {
- return 1;
- }
- else if ((int)$first[3] > (int)$second[3]) {
- return -1;
- }
- if ((int)$first[4] < (int)$second[4]) {
- return 1;
- }
- else if ((int)$first[4] > (int)$second[4]) {
- return -1;
- }
- return 0;
- }
- function ComparerResult($first, $second) {
- if ((int)$first[3] < (int)$second[3]) {
- return -1;
- }
- else if ((int)$first[3] > (int)$second[3]) {
- return 1;
- }
- if ((int)$first[4] < (int)$second[4]) {
- return -1;
- }
- else if ((int)$first[4] > (int)$second[4]) {
- return 1;
- }
- return 0;
- }
- function dComparerid($first, $second) {
- if ((int)$first[4] < (int)$second[4]) {
- return 1;
- }
- else if ((int)$first[4] > (int)$second[4]) {
- return -1;
- }
- return 0;
- }
- function Comparerid($first, $second) {
- if ((int)$first[4] < (int)$second[4]) {
- return -1;
- }
- else if ((int)$first[4] > (int)$second[4]) {
- return 1;
- }
- return 0;
- }
- function dComparerUsername($first, $second) {
- if ($first[3] < $second[3]) {
- return 1;
- }
- else if ($first[3] > $second[3]) {
- return -1;
- }
- if ((int)$first[4] < (int)$second[4]) {
- return 1;
- }
- else if ((int)$first[4] > (int)$second[4]) {
- return -1;
- }
- return 0;
- }
- function ComparerUsername($first, $second) {
- if ($first[3] < $second[3]) {
- return -1;
- }
- else if ($first[3] > $second[3]) {
- return 1;
- }
- if ((int)$first[4] < (int)$second[4]) {
- return -1;
- }
- else if ((int)$first[4] > (int)$second[4]) {
- return 1;
- }
- return 0;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement