gpt4 book ai didi

MYSQLi 和 Highcharts

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

我的 MYSQL 查询遇到问题。我可以将其发送到 Highcharts,但不太正确。我想获取上个月的温度并将其放入 Highcharts 中。我的查询有点有效,但只能获取每天的第一个温度,而且是在午夜之后。如何进行查询以获取一个月内每天每小时的温度?这是我的查询。很抱歉我无法正确设置此格式。

<?php
$con = mysqli_connect("localhost","root","root","manortsc_test");

if (!$con) {
die('Could not connect: ' . mysql_error());
}

$sth = mysqli_query($con,"
SELECT DateTime,T
FROM alldata
WHERE YEAR(DateTime) = YEAR(CURDATE()) AND MONTH(DateTime) = MONTH(CURDATE() - INTERVAL 1 MONTH)
GROUP BY YEAR(DateTime), MONTH(DateTime), DAY(DateTime)
"
);
$rows = array();
$rows['name'] = 'Outside';
while($r = mysqli_fetch_array($sth)) {
$rows['data'][] = $r['T'];
}
$sth = mysqli_query($con,"
SELECT DateTime,Ti
FROM alldata
WHERE YEAR(DateTime) = YEAR(CURDATE()) AND MONTH(DateTime) = MONTH(CURDATE() - INTERVAL 1 MONTH)
GROUP BY YEAR(DateTime), MONTH(DateTime), DAY(DateTime)
"
);
$rows1 = array();
$rows1['name'] = 'Inside';
while($rr = mysqli_fetch_assoc($sth)) {
$rows1['data'][] = $rr['Ti'];
}
$result = array();
array_push($result,$rows);
array_push($result,$rows1);

print json_encode($result, JSON_NUMERIC_CHECK);

mysqli_close($con);
?>

最佳答案

花了一晚上的时间研究并得出了答案。它只是获取该月每天的最大 T。我可以以此为基础。希望它对某人有帮助。

SELECT DateTime,max(T)
FROM alldata
WHERE YEAR(DateTime) = YEAR(CURDATE()) AND MONTH(DateTime) = MONTH(CURDATE() - INTERVAL 1 MONTH)
GROUP BY day(DateTime)

"

关于MYSQLi 和 Highcharts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40104055/

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