Länderdaten nach Regionen

Bitte wählen Sie die Region aus, deren Länder angezeigt werden sollen.

prepare($sql); $stmt->execute(); echo "Region "; // Ausgabe der Daten if(isset($_POST["region"]) && !empty($_POST["region"])){ try { $auswahl = "SELECT countries.name AS Land, countries.area AS 'Fläche', AVG(country_stats.gdp) AS 'AVG BIP', AVG(country_stats.population) AS 'AVG Bevölkerung', continents.name AS Kontinent from regions JOIN continents on continents.continent_id = regions.continent_id JOIN countries on regions.region_id = countries.region_id JOIN country_stats on countries.country_id = country_stats.country_id WHERE regions.region_id = :region_id GROUP BY countries.country_id, countries.name, countries.area, continents.name"; $stmt = $pdo->prepare($auswahl); $stmt->bindParam(':region_id', $_POST['region'], PDO::PARAM_INT); $stmt->execute(); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); if(count($results) > 0) { echo "

"; echo ""; echo ""; foreach($results as $row) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
LandFlächeAVG BIPAVG BevölkerungKontinent
" . htmlspecialchars($row['Land']) . "" . htmlspecialchars($row['Fläche'], 0, ',', '.') . "" . htmlspecialchars($row['AVG BIP'], 2, ',', '.') . "" . htmlspecialchars($row['AVG Bevölkerung'], 0, ',', '.') . "" . htmlspecialchars($row['Kontinent']) . "
"; } else { echo "

Keine Daten.

"; } } catch(PDOException $e) { echo "

Fehler bei der Datenbankabfrage: " . htmlspecialchars($e->getMessage()) . "

"; } } ?>