commit 6c3074841b90249301f7c657da6e6529040dc475
parent e0d1058350963ff6040c07599f039fc72006ffee
Author: LennartSchroot <[email protected]>
Date: Mon, 19 Jun 2023 00:42:22 +0200
xml meuk
Diffstat:
2 files changed, 24 insertions(+), 27 deletions(-)
diff --git a/Controller/hdata/hdata.php b/Controller/hdata/hdata.php
@@ -9,11 +9,11 @@ function make_table() {
header('Content-Disposition: attachment; filename="' . $filename . '"');
// Retrieve the XML data
- var_dump($key->retrieveHumidityTable('ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684', true));
+ $humidityXml = $key->retrieveHumidityTable('ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684', true);
$hDataXml = $key->retrieveHData('ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684', true);
// Output the XML data directly to the browser
- //echo "<weather><humidity>$humidityXml</humidity><hdata>$hDataXml</hdata></weather>";
+ echo "<weather><humidity>$humidityXml</humidity><hdata>$hDataXml</hdata></weather>";
exit();
} else {
diff --git a/Model/Key.php b/Model/Key.php
@@ -79,20 +79,19 @@ Class Key{
}
- function retrieveHumidityTable($key, $generateXml = false){
+ function retrieveHumidityTable($key, $generateXml = false) {
$html = '<table>';
$db = new mysqli("86.92.67.21", "friedel", "hailiwa", "wap2");
$query = "SELECT distinct temperature, dew_point, nl.name as city, date_time
- FROM weather_data wd
- JOIN station s ON wd.station_name = s.name
- JOIN contract_station cs ON cs.station_name = s.name
- JOIN nearestlocation nl ON nl.station_name = s.name
- JOIN country co ON co.country_code = nl.country_code
- JOIN geolocation geo ON geo.country_code = co.country_code
- JOIN contract c ON cs.contract_id = c.contract_id
- WHERE c.token = ?
- ORDER BY date_time DESC
- ";
+ FROM weather_data wd
+ JOIN station s ON wd.station_name = s.name
+ JOIN contract_station cs ON cs.station_name = s.name
+ JOIN nearestlocation nl ON nl.station_name = s.name
+ JOIN country co ON co.country_code = nl.country_code
+ JOIN geolocation geo ON geo.country_code = co.country_code
+ JOIN contract c ON cs.contract_id = c.contract_id
+ WHERE c.token = ?
+ ORDER BY date_time DESC";
$stmt = mysqli_prepare($db, $query);
$stmt->bind_param("s", $key);
$stmt->execute();
@@ -104,36 +103,33 @@ Class Key{
$table1 .= '<tr><th>Date</th><th>Humidity</th></tr>';
$table2 = '<tr><th id="tabledate" colspan="4">Kangding Humidity Data</th></tr>';
$table2 .= '<tr><th>Date</th><th>Humidity</th></tr>';
- $xml1 = '<location ="Chengdu">';
- $xml2 = '<location ="Kangding">';
+ $xml1 = '<location name="Chengdu">';
+ $xml2 = '<location name="Kangding">';
while ($row = $data->fetch_assoc()) {
$humidity = humid($row["temperature"], $row["dew_point"]);
$current_date = $row['date_time'];
$correct_date = date("d M Y H:i:s", strtotime($current_date));
$city = $row['city'];
-
$results[$city] = array();
-
$results[$city][] = array(
'date' => $correct_date,
'humidity' => $humidity
);
// Table and Generate XML
- if($city == 'Chengdu') {
- $table1 .= '<tr><td>'.$correct_date.'</td><td>'.$humidity.'</td></tr>';
- $xml1 .= '<date>'.$correct_date.'</date><humidity>'.$humidity.'</humidity>';
- }
- else{
- $table2 .= '<tr><td>'.$correct_date.'</td><td>'.$humidity.'</td></tr>';
- $xml2 .= '<date>'.$correct_date.'</date><humidity>'.$humidity.'</humidity>';
+ if ($city == 'Chengdu') {
+ $table1 .= '<tr><td>' . $correct_date . '</td><td>' . $humidity . '</td></tr>';
+ $xml1 .= '<data>' . '<date>' . $correct_date . '</date><humidity>' . $humidity . '</humidity>' . '</data>';
+ } else {
+ $table2 .= '<tr><td>' . $correct_date . '</td><td>' . $humidity . '</td></tr>';
+ $xml2 .= '<data>' . '<date>' . $correct_date . '</date><humidity>' . $humidity . '</humidity>' . '</data>';
}
}
- $xml1 = '</location>';
- $xml2 = '</location>';
- $xml = '<data>' . $xml1 . $xml2 . '</data>';
+ $xml1 .= '</location>';
+ $xml2 .= '</location>';
+ $xml = $xml1 . $xml2;
$html .= $table1 . $table2;
if ($generateXml) {
return $xml; // Return SimpleXMLElement object
@@ -141,6 +137,7 @@ Class Key{
return $html;
}
+
function retrieveHData($key, $generateXml = false) {
$html = '';
$db = new mysqli("86.92.67.21", "friedel", "hailiwa", "wap2");