Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>Table</title>
- </head>
- <body>
- <h1>File info</h1>
- <?php
- "<table>";
- $file = fopen("namesInfo.txt", "r") or die("Unable to open file!");
- $table = "<table border = \"1px\">";
- $table .= "<thead>";
- $table .= "<tr>";
- $table .= "<th>Name</th>";
- $table .= "<th>Salary</th>";
- $table .= "<th>Town</th>";
- $table .= "<th>Age</th>";
- $table .= "</tr>";
- $table .= "</thead>";
- $table .= "<tbody>";
- $countName = 0;
- $sumSalary = 0;
- $sumAge = 0;
- $towns = array();
- $index_of_town = 0;
- while(!feof($file)) {
- $currentRow = fgets($file);
- $splitCurrentRow = explode(" ", $currentRow);
- if(count($splitCurrentRow) !=1){
- $name = explode(":",$splitCurrentRow[0])[1];
- $salary = explode(":",$splitCurrentRow[1])[1];
- $town = explode(":",$splitCurrentRow[2])[1];
- $age = explode(":",$splitCurrentRow[3])[1];
- $table .= "<tr>";
- $table .= "<td>" . $name . "</td>";
- $table .= "<td>" . $salary . "</td>";
- $table .= "<td>" . $town . "</td>";
- $table .= "<td>" . $age . "</td>";
- $table .= "</tr>";
- $countName++;
- $sumSalary += $salary;
- $sumAge += $age;
- $index_of_town++;
- }
- }
- $averageAges = round($sumAge / $countName);
- $most_common_town = $towns[0];
- $table .= "</tbody>";
- $table .= "<tfoot>";
- $table .= "<tr>";
- $table .= "<td style=\"color:red\">" . $countName . "</td>";
- $table .= "<td style=\"color:red\">" . $sumSalary . "</td>";
- $table .= "<td style=\"color:red\">" . $towns . "</td>";
- $table .= "<td style=\"color:red\">" . $averageAges . "</td>";
- $table .= "</tr>";
- $table .= "</tfoot>";
- $table .= "</table>";
- echo $table;
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement