Advertisement
Xom9ik

Table Specialty (backend)

May 10th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.44 KB | None | 0 0
  1. <?php
  2.  
  3. require_once "db-unity/db.php";
  4.  
  5. $specialty = $_POST['specialty'];
  6. //$specialty = "Информатика"; // Example
  7. $users = R::findAll("users");
  8.  
  9. $array = [];
  10. $score = [];
  11. $j = 0;
  12.  
  13. foreach ($users as $user) {
  14.  
  15.     if($user->specialty_1 == $specialty) {
  16.         $array[$j] = $user;
  17.         $score[$j] = 1;
  18.         $j+=1;
  19.     }
  20.     else if ($user->specialty_2 == $specialty) {
  21.         $array[$j] = $user;
  22.         $score[$j] = 2;
  23.         $j+=1;
  24.     }
  25.     else if ($user->specialty_3 == $specialty) {
  26.         $array[$j] = $user;
  27.         $score[$j] = 3;
  28.         $j+=1;
  29.     }
  30. }
  31.  
  32. $output = "<h3>" . $specialty . "</h3><br>";
  33. $output .= " <table>
  34.        <thead>
  35.          <tr>
  36.              <th>Фамилия</th>
  37.              <th>Имя</th>
  38.              <th>Отчество</th>
  39.              <th>Рейтинговый балл</th>
  40.              <th>Приоритет</th>
  41.          </tr>
  42.        </thead>
  43.        <tbody>";
  44.  
  45. $rightArray = [];
  46.  
  47. for ($i = 0; $i < $j; $i += 1) {
  48.     $zno_score = "";
  49.     $priority = "";
  50.     if($score[$i] == 1)
  51.         $zno_score .= $array[$i]->zno_competition_score_1;
  52.     else if($score[$i] == 2)
  53.         $zno_score .= $array[$i]->zno_competition_score_2;
  54.     else if($score[$i] == 3)
  55.         $zno_score .= $array[$i]->zno_competition_score_3;
  56.  
  57.     if($score[$i] == 1)
  58.         $priority .= $array[$i]->priority_1;
  59.     else if($score[$i] == 2)
  60.         $priority .= $array[$i]->priority_2;
  61.     else if($score[$i] == 3)
  62.         $priority .= $array[$i]->priority_3;
  63.  
  64.     $rightArray[$i] = array(
  65.         'surname'  => $array[$i]->surname,
  66.         'name' => $array[$i]->name,
  67.         'middlename' =>  $array[$i]->middlename,
  68.         'zno_score'  => $zno_score,
  69.         'priority' => $priority
  70.         );
  71. }
  72.  
  73. for ($i=0; $i < count($rightArray); $i++) {
  74.     $sortkey[$i]=$rightArray[$i]['zno_score'];
  75. }
  76.  
  77. arsort($sortkey); // по возрастанию, arsort($sortkey) - по убыванию
  78.  
  79. foreach ($sortkey as $key => $key) {
  80.     $sorted[]=$rightArray[$key];
  81. }
  82.  
  83. for ($i = 0; $i < $j; $i += 1) {
  84.     $output .=
  85.         "<tr>
  86.            <td>" . $sorted[$i]['surname'] . "</td>
  87.            <td>" . $sorted[$i]['name'] . "</td>
  88.            <td>" . $sorted[$i]['middlename'] . "</td>
  89.            <td>" . $sorted[$i]['zno_score']. "</td>
  90.            <td>" . $sorted[$i]['priority'] . "</td>
  91.        </tr>";
  92. }
  93.  
  94. $output .= "</tbody>
  95.      </table>";
  96.  
  97. echo $output;
  98. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement