mercredi 5 août 2015

same date to be one date and want to be average temperature @one day in php


Following is my php code:

<?php 
  echo "<h1>test</h1>";
  echo "<table border = '1' width = '50%'>\n";
  echo "<tr>";
  echo "<th>date</th>";
  echo "<th>temperature</th>";


  //get data from file
  $fileName = 'sensor.csv';
  $file = fopen($fileName,"r");


  //while not to end of file
  while (!feof($file) ) 
  {

    while (($csv_line = fgetcsv($file)) !== FALSE)
    {

      $date_format = strtotime($csv_line[0]);
      //print_r($csv_line);
      echo "<tr>";    //beginning new row of record
      echo "<td>" . date("Y-m-d", $date_format)."</td>";  
      echo "<td>" . $csv_line[2]."</td>";  
      echo "</tr>"; //new row

    }
    echo "</table>\n";
  }

?>


The following is the current output

date        temperature
2015-07-20  22.7
2015-07-20  22.7
2015-07-20  22.8
2015-07-19  32.8
2015-07-19  31.9
2015-07-19  32.8
2015-07-19  32.8
2015-07-18  29.1
2015-07-18  28.8
2015-07-18  29.7
2015-07-18  29.9
2015-07-18  29.4
2015-07-18  29.8
2015-07-16  26.4
2015-07-16  25.9
2015-07-16  24.7
2015-07-16  24.9
2015-07-16  25
2015-07-16  26.4
2015-07-16  27
2015-07-16  26.1
2015-07-16  26

I want it to be like this:

date        temperature
2015-07-20  average temperature of each day
2015-07-19  average temperature of each day
2015-07-18  average temperature of each day
2015-07-16  average temperature of each day



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire