gpt4 book ai didi

php - 在sql数据库中按年份选择

转载 作者:行者123 更新时间:2023-11-29 20:56:12 24 4
gpt4 key购买 nike

我制作了这个网站:http://temperatur.co.nf/year.php它是一个温度记录器,每 1 小时获取最近 24 小时的平均读数并将其绘制在图表上。

我想更改此设置以显示 2015 年的所有读数以及每天的平均值。然后我想再次阅读 2016 年的数据。

问题:- 如何仅读取一年的数据?- 如何将两个不同年份的读数放在同一个图表中,以便两个读数位于同一日期?

我喜欢用图表来比较这两年

数据库有一列(时间)和一列温度(out_temp)

我当前的计划:

{
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);

}

最佳答案

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

关于php - 在sql数据库中按年份选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37609924/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com