Advertisement
TsetsoP

tupa tablica

Nov 3rd, 2021
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.82 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>Table</title>
  8. </head>
  9. <body>
  10.     <h1>File info</h1>
  11.     <?php
  12.    
  13.     $currentRow = "name: Ivan salary:5000 town:Sofia age:20 ";
  14.     $splitCurrentRow = explode(" ", $currentRow);
  15.  
  16.  
  17.     /*  $name = explode (":", $splitCurrentRow[0][1];
  18.     $salary = explode (":", $splitCurrentRow[1][1];
  19.     $towwn = explode (":", $splitCurrentRow[2][1];
  20.     $age = explode (":", $splitCurrentRow[3][1];
  21.     */
  22.  
  23.     /*echo"<pre>";
  24.     echo var_dump($name);
  25.     echo var_dump($salary);
  26.     echo var_dump($town);
  27.     echo var_dump($age);
  28.     echo"<pre>";
  29.     */
  30.        
  31.         $myfile = fopen("namesInfo.txt", "r") or die("Unable to open file!");
  32.  
  33.         $table = "<table border = \"1px\">";
  34.         $table .= "<thread>";
  35.         $table .= "<tr>";
  36.         $table .= "<th>Name</th>";
  37.         $table .= "<th>Salary</th>";
  38.         $table .= "<th>Town</th>";
  39.         $table .= "<th>Age</th>";
  40.         $table .= "</tr>";
  41.         $table .= "</thread>";
  42.  
  43.         $table .= "<tbody>"
  44.  
  45.         $countName = 0;
  46.         $sumSalary = 0;
  47.         $sumAge = 0;
  48.         $towns = array();
  49.        
  50.         while(!feof($myfile)) {
  51.             $currentRow = fgets($myfile);
  52.             $splitCurrentRow = explode("",$currentRow);
  53.             if(count($splitCurrentRow) != 1){
  54.                 $name = explode(":", $splitCurrentRow[0])[1];
  55.                 $salary = explode(":", $splitCurrentRow[1])[1];
  56.                 $town = explode(":", $splitCurrentRow[2])[1];
  57.                 $age = explode(":", $splitCurrentRow[3])[1];
  58.  
  59.                 $table .= "<tr>";
  60.                 $table .= "<td>". $name. "</td>";
  61.                 $table .= "<td>". $salary. "</td>";
  62.                 $table .= "<td>". $town. "</td>";
  63.                 $table .= "<td>". $age. "</td>";
  64.                 $table .= "</tr>";
  65.                 $countName++;
  66.                 $sumSalary += $salary;
  67.                 $sumAge += $age;
  68.                 $towns[] = $town;
  69.             }
  70.          
  71.         }
  72.  
  73.         $averageAges = round($sumAges / $countName);
  74.  
  75.         $table .= "</tbody>";
  76.         $table .= "<tfoot>";
  77.         $table .=     "<tr>";
  78.         $table .=           "<td style =\"color:red\">Count name: " . $countName . "</td>";
  79.         $table .=           "<td style =\"color:red\">Sum salary: " . $sumSalary . "</td>";
  80.         $table .=           "<td style =\"color:red\"> " . $towns . "</td>";
  81.         $table .=           "<td style =\"color:red\"> " . $averageAges . "</td>";
  82.         $table .=     "</tr>";
  83.         $table .= "</tfoot>";
  84.         $table .= "</table>";
  85.        
  86.         echo $table;
  87.    
  88.        
  89.        
  90.     ?>
  91. </body>
  92. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement