Advertisement
TsetsoP

Table

Nov 3rd, 2021 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>Table</title>
  5. </head>
  6. <body>
  7. <h1>File info</h1>
  8. <?php
  9.  
  10. "<table>";
  11. $file = fopen("namesInfo.txt", "r") or die("Unable to open file!");
  12.  
  13. $table = "<table border = \"1px\">";
  14. $table .= "<thead>";
  15. $table .= "<tr>";
  16. $table .= "<th>Name</th>";
  17. $table .= "<th>Salary</th>";
  18. $table .= "<th>Town</th>";
  19. $table .= "<th>Age</th>";
  20. $table .= "</tr>";
  21. $table .= "</thead>";
  22. $table .= "<tbody>";
  23.  
  24. $countName = 0;
  25. $sumSalary = 0;
  26. $sumAge = 0;
  27. $towns = array();
  28. $index_of_town = 0;
  29.  
  30. while(!feof($file)) {
  31. $currentRow = fgets($file);
  32. $splitCurrentRow = explode(" ", $currentRow);
  33. if(count($splitCurrentRow) !=1){
  34. $name = explode(":",$splitCurrentRow[0])[1];
  35. $salary = explode(":",$splitCurrentRow[1])[1];
  36. $town = explode(":",$splitCurrentRow[2])[1];
  37. $age = explode(":",$splitCurrentRow[3])[1];
  38.  
  39. $table .= "<tr>";
  40. $table .= "<td>" . $name . "</td>";
  41. $table .= "<td>" . $salary . "</td>";
  42. $table .= "<td>" . $town . "</td>";
  43. $table .= "<td>" . $age . "</td>";
  44. $table .= "</tr>";
  45. $countName++;
  46. $sumSalary += $salary;
  47. $sumAge += $age;
  48. $index_of_town++;
  49.  
  50. }
  51. }
  52. $averageAges = round($sumAge / $countName);
  53. $most_common_town = $towns[0];
  54.  
  55. $table .= "</tbody>";
  56. $table .= "<tfoot>";
  57. $table .= "<tr>";
  58. $table .= "<td style=\"color:red\">" . $countName . "</td>";
  59. $table .= "<td style=\"color:red\">" . $sumSalary . "</td>";
  60. $table .= "<td style=\"color:red\">" . $towns . "</td>";
  61. $table .= "<td style=\"color:red\">" . $averageAges . "</td>";
  62. $table .= "</tr>";
  63. $table .= "</tfoot>";
  64. $table .= "</table>";
  65.  
  66. echo $table;
  67.  
  68. ?>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement