First, I'm not experienced with PHP whatsoever. I have 2 arrays - minimumpressure and maximumpressure. They both access data from a database and to create a simple xml file as you can see below:-
<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>
The problem is, as you can see, the 1st value of the minimum array is always equal to the last value of the maximum array ( in this case "1001"). These arrays are overwritten every half hour or so with new values, yet the the problem still exists. Here's the code I use:-
$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;
}
And here's the code used to create the xml file:-
$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')
Note: I've checked the data in the database and it's correct, so it's clearly the script that's the problem. Sorry for the long question and code sample, hopefully someone can help.
#####$$$$$ Update $$$$$$####### It seems the SQL script isn't the problem. I've left the interval at 24, and when I run the SQL script in my SQL workbench it's loading the correct results.
However when it's run from the script above, the first element is always equal to the last element. IE. (minpressure[0] == minpressure[23])
Any further thoughts?