Voll Upload SGD Fachinformatiker PHP
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Länderdaten nach Regionen</title>
|
||||
<?php
|
||||
include_once("db.inc.php");
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Länderdaten nach Regionen</h1>
|
||||
<p>Bitte wählen Sie die Region aus, deren Länder angezeigt werden sollen.</p>
|
||||
<form method="post">
|
||||
<?php
|
||||
// Select-Auswahl für Regionen
|
||||
$sql = "SELECT region_id, name FROM regions ORDER BY name";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
echo "Region <select name='region' id='region'>";
|
||||
echo "<option value=''>Region wählen</option>";
|
||||
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $region) {
|
||||
$selected = (isset($_POST['region']) && $_POST['region'] == $region['region_id']) ? 'selected' : '';
|
||||
echo "<option value='" . htmlspecialchars($region['region_id']) . "' $selected>" .
|
||||
htmlspecialchars($region['name']) . "</option>";
|
||||
}
|
||||
echo "</select>";
|
||||
|
||||
// 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 "<br> <br>";
|
||||
echo "<table border='3'>";
|
||||
echo "<tr><th>Land</th><th>Fläche</th><th>AVG BIP</th><th>AVG Bevölkerung</th><th>Kontinent</th></tr>";
|
||||
|
||||
foreach($results as $row) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . htmlspecialchars($row['Land']) . "</td>";
|
||||
echo "<td>" . htmlspecialchars($row['Fläche'], 0, ',', '.') . "</td>";
|
||||
echo "<td>" . htmlspecialchars($row['AVG BIP'], 2, ',', '.') . "</td>";
|
||||
echo "<td>" . htmlspecialchars($row['AVG Bevölkerung'], 0, ',', '.') . "</td>";
|
||||
echo "<td>" . htmlspecialchars($row['Kontinent']) . "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
} else {
|
||||
echo "<p>Keine Daten.</p>";
|
||||
}
|
||||
} catch(PDOException $e) {
|
||||
echo "<p>Fehler bei der Datenbankabfrage: " . htmlspecialchars($e->getMessage()) . "</p>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
<br>
|
||||
<input type="submit" value="anzeigen">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
$dbuser = 'root';
|
||||
$dbpw = 'Feuerwehr1!';
|
||||
$dbhost = 'localhost';
|
||||
$dbname = 'nation';
|
||||
|
||||
try {
|
||||
$pdo = new PDO ("mysql:dbname=$dbname;host=$dbhost;charset=utf8", $dbuser, $dbpw);
|
||||
} catch (PDOException $e) {
|
||||
die ($e->getMessage());
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||
<title>e3_artikel_löschen</title>
|
||||
|
||||
<?php
|
||||
require_once("bestellen.class.php")
|
||||
?>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>Artikel Löschen</h1>
|
||||
|
||||
|
||||
<div class="ausgabe">
|
||||
<?php
|
||||
|
||||
$bestell = new Bestell();
|
||||
|
||||
// Prüfen ob Formular abgeschickt wurde
|
||||
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['anr'])) {
|
||||
$anr = $_POST['anr'];
|
||||
$bestell->loeschen($anr);
|
||||
}
|
||||
|
||||
?>
|
||||
<!-- Formularfelder erstellen -->
|
||||
<form method="post">
|
||||
<label for="anr">Artikel: </label>
|
||||
<?php echo $bestell->einfuegenSelect("artikel", "anr" ,"name", "anr"); ?>
|
||||
<input type="submit" value="auswahl">
|
||||
|
||||
</form>
|
||||
<?php
|
||||
|
||||
?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
include_once("db.inc.php");
|
||||
|
||||
$selected_region = $_GET['region'] ?? 'Caribbean';
|
||||
|
||||
// Regionen für Dropdown aus Tabelle regions holen
|
||||
$stmt_regions = $pdo->query("SELECT region_name FROM regions ORDER BY region_name");
|
||||
$regions = $stmt_regions->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
|
||||
$sql = "
|
||||
SELECT
|
||||
country_name,
|
||||
area,
|
||||
AVG(gdp) as avg_gdp,
|
||||
AVG(population) as avg_population,
|
||||
continent
|
||||
FROM nation
|
||||
WHERE region = :region
|
||||
GROUP BY country_name, area, continent
|
||||
ORDER BY country_name
|
||||
";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute(['region' => $selected_region]);
|
||||
$countries = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Länderdaten nach Regionen</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; margin: 40px; }
|
||||
h1 { color: #333; }
|
||||
h2 { color: #666; margin-top: 30px; }
|
||||
form { margin: 20px 0; padding: 20px; background: #f5f5f5; border-radius: 8px; }
|
||||
select, button { padding: 8px 12px; font-size: 16px; }
|
||||
table { border-collapse: collapse; width: 100%; margin-top: 20px; }
|
||||
th, td { border: 1px solid #ddd; padding: 12px; text-align: left; }
|
||||
th { background-color: #4CAF50; color: white; }
|
||||
tr:nth-child(even) { background-color: #f2f2f2; }
|
||||
.number { text-align: right; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Länderdaten nach Regionen</h1>
|
||||
<p>Bitte wählen Sie die Region aus, deren Länder angezeigt werden sollen.</p>
|
||||
|
||||
<form method="GET" action="">
|
||||
<h2>Region |
|
||||
<select name="region" onchange="this.form.submit()">
|
||||
<?php foreach ($regions as $region): ?>
|
||||
<option value="<?= htmlspecialchars($region) ?>"
|
||||
<?= $region == $selected_region ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($region) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</h2>
|
||||
<button type="submit">anzeigen</button>
|
||||
</form>
|
||||
|
||||
<?php if (!empty($countries)): ?>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Land</th>
|
||||
<th class="number">Fläche</th>
|
||||
<th class="number">AVG BIP</th>
|
||||
<th class="number">AVG Bevälkerung</th>
|
||||
<th>Kontinent</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($countries as $country): ?>
|
||||
<tr>
|
||||
<td><?= htmlspecialchars($country['country_name']) ?></td>
|
||||
<td class="number"><?= number_format($country['area'], 2) ?></td>
|
||||
<td class="number"><?= number_format($country['avg_gdp'], 4) ?></td>
|
||||
<td class="number"><?= number_format($country['avg_population'], 4) ?></td>
|
||||
<td><?= htmlspecialchars($country['continent']) ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php elseif ($_SERVER['REQUEST_METHOD'] === 'GET'): ?>
|
||||
<p>Keine Daten für die ausgewählte Region gefunden.</p>
|
||||
<?php endif; ?>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,45 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Länderdaten nach Regionen</title>
|
||||
<?php
|
||||
try {
|
||||
$pdo = new PDO ( 'mysql:dbname=nation;charset=utf8', 'root', 'Feuerwehr1!' );
|
||||
//$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
//$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
||||
} catch ( PDOException $e ) {
|
||||
die ( $e->getMessage () );
|
||||
}
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
<form method="post">
|
||||
<?php
|
||||
$sql = "SELECT name FROM regions ORDER BY name";
|
||||
$stmt = $pdo -> prepare($sql);
|
||||
$stmt->execute();
|
||||
//print_r($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||
echo "<select name ='konti' id = 'konti'>";
|
||||
foreach ($stmt->fetchAll(PDO::FETCH_COLUMN,0) as $daten)
|
||||
echo "<option value = $daten>".$daten."</option>";
|
||||
echo "</select>";
|
||||
|
||||
|
||||
|
||||
if(isset($_POST["konti"])){
|
||||
print_r($_POST["konti"]);
|
||||
$auswahl = "SELECT countries.name, countries.area, country_stats.gdp AS 'AVG BIP', country_stats.population, continents.name FROM
|
||||
countries, country_stats, regions INNER JOIN continents ON regions.continent_id = continents.continent_id
|
||||
WHERE regions.region_id = countries.region_id && countries.country_id = country_stats.country_id AND regions.name ='". $_POST['konti']."' GROUP BY countries.country_id";
|
||||
$stmt = $pdo->prepare($auswahl);
|
||||
$ausgabe[] = $stmt->execute();
|
||||
foreach ($ausgabe as $ausgeben)
|
||||
echo $ausgeben;
|
||||
}
|
||||
?>
|
||||
<br>
|
||||
<input type = "submit" value ="anzeigen">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,68 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Länderdaten nach Regionen</title>
|
||||
<?php
|
||||
include_once("db.inc.php");
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
<form method="post">
|
||||
<?php
|
||||
// Select-Auswahl für Regionen
|
||||
$sql = "SELECT region_id, name FROM regions ORDER BY name";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
echo "<select name='region' id='region'>";
|
||||
echo "<option value=''>Region wählen</option>";
|
||||
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $region) {
|
||||
$selected = (isset($_POST['region']) && $_POST['region'] == $region['region_id']) ? 'selected' : '';
|
||||
echo "<option value='" . htmlspecialchars($region['region_id']) . "' $selected>" .
|
||||
htmlspecialchars($region['name']) . "</option>";
|
||||
}
|
||||
echo "</select>";
|
||||
|
||||
// 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 "<h2>Länder in der ausgewählten Region:</h2>";
|
||||
echo "<table border='1'>";
|
||||
echo "<tr><th>Land</th><th>Fläche</th><th>AVG BIP</th><th>AVG Bevölkerung</th><th>Kontinent</th></tr>";
|
||||
|
||||
foreach($results as $row) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . htmlspecialchars($row['Land']) . "</td>";
|
||||
echo "<td>" . number_format($row['Fläche'], 0, ',', '.') . "</td>";
|
||||
echo "<td>" . number_format($row['AVG BIP'], 2, ',', '.') . "</td>";
|
||||
echo "<td>" . number_format($row['AVG Bevölkerung'], 0, ',', '.') . "</td>";
|
||||
echo "<td>" . htmlspecialchars($row['Kontinent']) . "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
} else {
|
||||
echo "<p>Keine Daten.</p>";
|
||||
}
|
||||
} catch(PDOException $e) {
|
||||
echo "<p>Fehler bei der Datenbankabfrage: " . htmlspecialchars($e->getMessage()) . "</p>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
<br>
|
||||
<input type="submit" value="anzeigen">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user