0

I made this website: http://temperatur.co.nf/year.php it is a temperature logger that takes the last 24 hours of readings with avrage every 1 hour and draws it on a graph.

I want to change this to show all readings from 2015 with avrage from every day. then i want to get a second reading with data from 2016.

Issues: - how to read data from one year only? - how to put readings from two different years in same graph, so that the two readings are on same date?

I like to compare the two years using the graph

Database has a column (time) and a column with temperatures (out_temp)

My current program:

{
        var data1 = google.visualization.arrayToDataTable(
                [
                      ['date','Outdoor'],
                      <?php


                      // select average readings      select * from readings where year(date) = 2015 
                      $result = mysql_query("SELECT DATE_FORMAT( date  , '%d.%c.%y %H:%i') AS Time1, AVG( out_temp ) AS out_temp FROM $table WHERE TIMESTAMPDIFF(HOUR,date, now()) < $hours GROUP BY ROUND( UNIX_TIMESTAMP( date ) DIV ($avg*3600) ) ");
                      if ($result !== false) 

                      {
                               $num=mysql_numrows($result);
                               $i=0;
                               while ($i < $num) 

                               {
                                $time=mysql_result($result,$i,"Time1");
                                $out_temp=mysql_result($result,$i,"out_temp");

                                echo "['";
                                echo "$time";
                                echo "',";
                                echo "$out_temp";
                                echo "]";
                                if ($i < ($num - 1)){
                                 echo ",";
                                }
                                $i++;
                               }

                      }

                      ?>
                ]);


        var options1 =  
        {
              title: 'Temperatures',
              curveType: 'function',
              legend: {position: 'bottom'},

              animation:{duration: 1000,easing: 'in',startup: true},

              vAxis: {viewWindowMode:'explicit',viewWindow: {max:35,min:-10} }
        };




        var chartA = new google.visualization.LineChart(document.getElementById('chart_div'));
        chartA.draw(data1, options1);

}

jarlh
  • 42,561
  • 8
  • 45
  • 63
  • Side note: you should not use mysql_* functions http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – rap-2-h Jun 03 '16 at 09:26

1 Answers1

0

how to read data from one year only?

select * from table where YEAR(date_field)=2016

how to put readings from two different years in same graph, so that the two readings are on same date?

select * from table where YEAR(date_field)=2016 or YEAR(date_field)=2015
Jehy
  • 4,729
  • 1
  • 38
  • 55