hanze/iwa-panda2

xml (7a2445c250dd0d35b645b172f00205b149735f1d)
Repositories | README.md

commit 7a2445c250dd0d35b645b172f00205b149735f1d
parent 6c3074841b90249301f7c657da6e6529040dc475
Author: LennartSchroot <[email protected]>
Date:   Mon, 19 Jun 2023 01:52:29 +0200

xml

Diffstat:
MController/hdata/hdata.php2+-
MModel/Key.php38+++++++++++---------------------------
Mcss/hdata.css2+-
3 files changed, 13 insertions(+), 29 deletions(-)

diff --git a/Controller/hdata/hdata.php b/Controller/hdata/hdata.php @@ -13,7 +13,7 @@ function make_table() { $hDataXml = $key->retrieveHData('ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684', true); // Output the XML data directly to the browser - echo "<weather><humidity>$humidityXml</humidity><hdata>$hDataXml</hdata></weather>"; + echo '<weather>' . $humidityXml . $hDataXml . '</weather>'; exit(); } else { diff --git a/Model/Key.php b/Model/Key.php @@ -140,6 +140,7 @@ Class Key{ function retrieveHData($key, $generateXml = false) { $html = ''; + $citycity = ''; $db = new mysqli("86.92.67.21", "friedel", "hailiwa", "wap2"); $query = "SELECT distinct temperature, wind_speed, dew_point, DATE(date_time) AS date, nl.name as city FROM weather_data wd @@ -157,12 +158,12 @@ Class Key{ $stmt->bind_param("s", $key); $stmt->execute(); $data = $stmt->get_result(); + $xml = '<WCTPD name="Windchill corrected temperature per day">'; $results = array(); $locations = array(); while ($row = $data->fetch_assoc()) { - $humidity = humid($row["temperature"], $row["dew_point"]); $wind_chill = windchill($row["temperature"], $row["wind_speed"]); $current_date = $row['date']; $city = $row['city']; @@ -176,55 +177,38 @@ Class Key{ $results[$current_date][] = array( 'city' => $city, 'windchill' => $wind_chill, - 'humidity' => $humidity ); $locations[$current_date][] = $city; } } - - if (!$generateXml){ $html .= $this->retrieveHumidityTable('ae9c50dc5cd58c538a0d6aedb17fffedcaffd568d22381dab3ae72baaeb24684'); - + $html .= '<table id="htmlTable">'; $html .= '<div class="space"></div>'; $html .= '<div class="content-title"><h2>Windchill corrected temperature per day</h2></div>'; - + foreach ($results as $date => $entries) { $html .= '<tr><th id="tabledate" colspan="4">' . date("d M Y", strtotime($date)) . '</th></tr>'; $html .= '<tr><th>Location</th><th>Windchill</th></tr>'; - + foreach ($entries as $entry) { + $citycity = $entry['city']; + $xml .= '<data>' . '<city>' . $citycity . '</city>' . '<wind_chill>' . $entry['windchill'] . '</wind_chill>' . '</data>'; $html .= '<tr>'; $html .= '<td>'.$entry['city'].'</td>'; $html .= '<td>'.$entry['windchill'].'</td>'; $html .= '</tr>'; } } - + $html .= '</table>'; $html .= '<a href="?downloadXml=true" class="download-button">Download XML</a>'; - - return $html; - } else { - $xml = '<data>'; - - foreach ($results as $date => $entries) { - $xml .= "<date at='$date'>"; - foreach ($entries as $entry) { - $xml .= '<location>'; - $xml .= "<city>{$entry['city']}</city>"; - $xml .= "<windchill>{$entry['windchill']}</windchill>"; - $xml .= "<humidity>{$entry['humidity']}</humidity>"; - $xml .= '</location>'; - } - $xml .= '</date>'; - } - - $xml .= '</data>'; - + $xml .= '</WCTPD>'; + if ($generateXml) { return $xml; // Return SimpleXMLElement object } + return $html; } } diff --git a/css/hdata.css b/css/hdata.css @@ -127,7 +127,7 @@ table { width: 100%; border-collapse: collapse; box-shadow: 0 0 10px #333333; - + color: white; } th, td {