<?php
header('Content-type: text/xml');
include '../../db/db_pumps.php';
$maxStations=50;

$query="Select Stations.ID, Stations.Name, Stations.Brand, Stations.Latitude, Stations.Longitude, Stations.Address1, Stations.Address2, Stations.Zone, Stations.County, Prices.Price, Prices.FuelType, Prices.DateUpdated, Prices.Updater, Prices.LatestPrice, Prices.Trend from Stations, Prices where Stations.ID = Prices.StationID AND FuelType='" . $_GET['type'] . "' AND Prices.LatestPrice='True' AND Prices.Price>50 AND `status` ='operating' AND Stations.Zone='" . $_GET['area'] ."' AND  Stations.county='" . $_GET['county'] . "' Order By Prices.Price ASC, Prices.DateUpdated DESC";

$result=mysql_query($query);
$resultCount=mysql_numrows($result);

$rows=0;
if ($resultCount>$maxStations){
     $rows=$maxStations;
}else{
     $rows=$resultCount;
}

echo "<stations totalFound=\"$resultCount\" totalReturned=\"$rows\">\n";

for ($i=0; $i<mysql_numrows($result); $i++){
	$ID=mysql_result($result,$i,"ID");
	$viewedIDs = $viewedIDs . $ID;
	$viewIDs = $viewedIDs . ',' . $ID . ',';
	$Latitude=mysql_result($result,$i,"Latitude");
	$Longitude=mysql_result($result,$i,"Longitude");
	$Name=mysql_result($result,$i,"Name");
	$Brand=mysql_result($result,$i,"Brand");
	$Address1=mysql_result($result,$i,"Address1");
	$Address2=mysql_result($result,$i,"Address2");
	$Price=mysql_result($result,$i,"Price");
	$Fuel=mysql_result($result,$i,"FuelType");
	$Trend=mysql_result($result,$i,"Trend");
	$DateUpdated=mysql_result($result,$i,"DateUpdated");
	$DateUpdatedShort=date("jS M", strtotime(mysql_result($result,$i,"DateUpdated")));
	$Updater=mysql_result($result,$i,"Updater");
	$Zone=mysql_result($result,$i,"Zone");
	$County=mysql_result($result,$i,"County");

	echo "<station ID=\"$ID\" Lat=\"$Latitude\" Lng=\"$Longitude\" name=\"$Name\" brand=\"$Brand\" addr1=\"$Address1\" addr2=\"$Address2\" price=\"$Price\" fuel=\"$Fuel\" trend=\"$Trend\" dateupdated=\"$DateUpdated\" dateupdatedshort=\"$DateUpdatedShort\"  Updater=\"$Updater\" Zone=\"$Zone\" County=\"$County\"/>\n";

}

mysql_close();
echo "</stations>";
?>