首先,我对 PHP 没有任何经验。我有 2 个阵列 - 最小压力和最大压力。他们都从数据库访问数据并创建一个简单的 xml 文件,如下所示:-
<pressuremaxhourly>1010,1009,1009,1009,1008,1008,1007,1005,1004,1003,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1001,1001,1001</pressuremaxhourly>
<pressureminhourly>1001,1009,1009,1008,1008,1006,1005,1004,1003,1002,1002,1002,1002,1002,1002,1002,1002,1002,1002,1001,1001,1001,1001,1001</pressureminhourly>
问题是,如您所见,最小数组的第一个值始终等于最大数组的最后一个值(在本例中为“1001”)。这些数组每半小时左右被新值覆盖一次,但问题仍然存在。这是我使用的代码:-
$MaxPressure="select hour(datetime) AS hour, max(BarometricPressure) as MAXBP from minute WHERE DATETIME
BETWEEN (CURDATE() + INTERVAL (SELECT hour(NOW())) hour - INTERVAL 24 hour)
AND ((CURDATE() + INTERVAL (SELECT hour(NOW()))hour))
group by hour
order by (CURDATE() + INTERVAL (SELECT hour(NOW())) hour - INTERVAL 24 hour)";
$MaxPressureResult = mysql_query($MaxPressure) or die('Failed to query'.mysql_error());
while ($row = mysql_fetch_object($MaxPressureResult)) {
$maxpressure[]=$row->MAXBP;
}
$MinimumPressure="select hour(datetime) AS hour, min(BarometricPressure) as MINBP from minute WHERE DATETIME
BETWEEN (CURDATE() + INTERVAL (SELECT hour(NOW())) hour - INTERVAL 24 hour)
AND ((CURDATE() + INTERVAL (SELECT hour(NOW()))hour))
group by hour
order by (CURDATE() + INTERVAL (SELECT hour(NOW())) hour - INTERVAL 24 hour)";
$MinimumPressureResult = mysql_query($MinimumPressure) or die('Failed to query'.mysql_error());
while ($minrow = mysql_fetch_object($MinimumPressureResult)) {
$minimumpressure[]=$minrow->MINBP;
}
这是用于创建 xml 文件的代码:-
$dom = new DOMDocument();
$root = $dom->createElement( "weatherdata" );
$dom->appendChild( $root );
$item = $dom->createElement( 'item', "" );
$root->appendChild($item);
$maxpressure = $dom->createElement( 'pressuremaxhourly', "$maxpressure[0],$maxpressure[1],$maxpressure[2],$maxpressure[3],$maxpressure[4], etc....for all values );
$item ->appendChild($maxpressure);
$minimumpressure = $dom->createElement( 'pressureminhourly', "$minimumpressure[0],$minimumpressure[1],$minimumpressure[2],$minimumpressure[3],$minimumpressure[4], etc....for all values );
$item ->appendChild($minimumpressure);
$dom->formatOutput = true;
$dom->save('Hourly.xml')
注意:我已经检查了数据库中的数据并且它是正确的,所以很明显是脚本有问题。对不起,很长的问题和代码示例,希望有人可以提供帮助。
#####$$$$$ 更新 $$$$$$####### 似乎 SQL 脚本不是问题所在。我将时间间隔设置为 24,当我在我的 SQL 工作台中运行 SQL 脚本时,它正在加载正确的结果。
然而,当它从上面的脚本运行时,第一个元素总是等于最后一个元素。IE。(minpressure[0] == minpressure[23])
还有什么想法吗?