Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Table</title>
- <style>
- table, th, td {
- border: 1px solid red;
- }
- th{
- color: #943126;
- }
- h1{
- color: darkblue;
- }
- </style>
- </head>
- <body>
- <h1>Homework - File Information</h1>
- <table>
- <thead>
- <tr>
- <th>Name</th>
- <th>Salary</th>
- <th>Town</th>
- <th>Age</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $myfile = fopen("namesInfo.txt", "r") or die("Unable to open file!");
- $all_names = array();
- $all_salaries = array();
- $all_towns = [];
- $all_ages = array();
- $sum = 0;
- $sumAge = 0;
- while(!feof($myfile)) {
- $data = fgets($myfile);
- $splitElement = explode(" ", $data);
- $name = explode(":", $splitElement[0]);
- $salary = explode(":", $splitElement[1]);
- $town = explode(":", $splitElement[2]);
- $age = explode(":", $splitElement[3]);
- array_push($all_names,$name[1]);
- array_push($all_salaries,$salary[1]);
- array_push($all_towns,$town[1]);
- array_push($all_ages,$age[1]);
- $sum += $salary[1];
- $sumAge += $age[1];
- echo "<tr>";
- echo "<td>".$name[1]."</td>";
- echo "<td>".$salary[1]."</td>";
- echo "<td>".$town[1]."</td>";
- echo "<td>".$age[1]."</td>";
- echo "</tr>";
- }
- fclose($myfile);
- ?>
- </tbody>
- <tfoot>
- <?php
- $average = $sumAge/count($all_ages);
- $count = 0;
- $currentCount = 0;
- $currTown;
- for ($i=0; $i < count($all_towns); $i++) {
- $str = $all_towns[$i];
- $currentCount = 0;
- for ($j=0; $j < count($all_towns); $j++) {
- if(strcmp($all_towns[$j],$str) == 0){
- $currentCount++;
- }
- }
- if($currentCount > $count){
- $count = $currentCount;
- $currTown = $str;
- }
- }
- echo "<tr>";
- echo "<td>Names : ".count($all_names)."</td>";
- echo "<td>Salary sum: ".$sum."</td>";
- echo "<td>Common town: ".$currTown."</td>";
- echo "<td>Age: ".number_format($average, 0)."</td>";
- echo "</tr>";
- ?>
- </tfoot>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment