mirror of
https://github.com/janunger/rheinwerk-video-training.git
synced 2026-02-06 07:05:14 +01:00
Initiale Version
This commit is contained in:
26
Kapitel_5/Lektion_4/warenkorb/_applikation.php
Executable file
26
Kapitel_5/Lektion_4/warenkorb/_applikation.php
Executable file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['warenkorb'])) {
|
||||
$_SESSION['warenkorb'] = [];
|
||||
}
|
||||
|
||||
function holeSortiment()
|
||||
{
|
||||
return [
|
||||
1 => 'Moderne Webseiten entwickeln',
|
||||
2 => 'PHP 7 und MySQL - Das umfassende Handbuch',
|
||||
3 => 'Der große Fotokurs - Richtig fotografieren lernen'
|
||||
];
|
||||
}
|
||||
|
||||
function zaehleWarenkorb()
|
||||
{
|
||||
$ergebnis = 0;
|
||||
foreach ($_SESSION['warenkorb'] as $artikelId => $anzahl) {
|
||||
$ergebnis += $anzahl;
|
||||
}
|
||||
|
||||
return $ergebnis;
|
||||
}
|
||||
24
Kapitel_5/Lektion_4/warenkorb/index.php
Executable file
24
Kapitel_5/Lektion_4/warenkorb/index.php
Executable file
@@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Artikelliste</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>
|
||||
Ihr Warenkorb ist leer.
|
||||
- <a href="warenkorb.php">Warenkorb anzeigen</a>
|
||||
</p>
|
||||
|
||||
<h1>Unser Angebot</h1>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Moderne Webseiten entwickeln</td>
|
||||
<td><a href="index.php?hinzufuegen=1">In den Warenkorb</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
34
Kapitel_5/Lektion_4/warenkorb/warenkorb.php
Executable file
34
Kapitel_5/Lektion_4/warenkorb/warenkorb.php
Executable file
@@ -0,0 +1,34 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Warenkorb</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Ihr Warenkorb</h1>
|
||||
|
||||
<form action="warenkorb.php" method="post">
|
||||
<table>
|
||||
<tr>
|
||||
<th>Bezeichnung</th>
|
||||
<th>Anzahl</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Moderne Webseiten entwickeln</td>
|
||||
<td>
|
||||
<input type="text"
|
||||
name="artikel[1]"
|
||||
value="1"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<button type="submit" name="aktualisieren">Aktualisieren</button>
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<p><a href="index.php">Zur Produktauswahl</a></p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
26
Kapitel_5/Lektion_4/warenkorb_loesung/_applikation.php
Executable file
26
Kapitel_5/Lektion_4/warenkorb_loesung/_applikation.php
Executable file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['warenkorb'])) {
|
||||
$_SESSION['warenkorb'] = [];
|
||||
}
|
||||
|
||||
function holeSortiment()
|
||||
{
|
||||
return [
|
||||
1 => 'Moderne Webseiten entwickeln',
|
||||
2 => 'PHP 7 und MySQL - Das umfassende Handbuch',
|
||||
3 => 'Der große Fotokurs - Richtig fotografieren lernen'
|
||||
];
|
||||
}
|
||||
|
||||
function zaehleWarenkorb()
|
||||
{
|
||||
$ergebnis = 0;
|
||||
foreach ($_SESSION['warenkorb'] as $artikelId => $anzahl) {
|
||||
$ergebnis += $anzahl;
|
||||
}
|
||||
|
||||
return $ergebnis;
|
||||
}
|
||||
46
Kapitel_5/Lektion_4/warenkorb_loesung/index.php
Executable file
46
Kapitel_5/Lektion_4/warenkorb_loesung/index.php
Executable file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/_applikation.php';
|
||||
|
||||
if (isset($_GET['hinzufuegen'])) {
|
||||
$artikelId = $_GET['hinzufuegen'];
|
||||
if (!isset($_SESSION['warenkorb'][$artikelId])) {
|
||||
$_SESSION['warenkorb'][$artikelId] = 0;
|
||||
}
|
||||
$_SESSION['warenkorb'][$artikelId]++;
|
||||
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Artikelliste</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>
|
||||
<?php if (zaehleWarenkorb() == 0): ?>
|
||||
Ihr Warenkorb ist leer.
|
||||
<?php else: ?>
|
||||
Ihr Warenkorb enthält <?= htmlspecialchars(zaehleWarenkorb()); ?> Artikel.
|
||||
<?php endif; ?>
|
||||
- <a href="warenkorb.php">Warenkorb anzeigen</a>
|
||||
</p>
|
||||
|
||||
<h1>Unser Angebot</h1>
|
||||
<table>
|
||||
<?php foreach (holeSortiment() as $artikelId => $artikel) : ?>
|
||||
<tr>
|
||||
<td><?= htmlspecialchars($artikel); ?></td>
|
||||
<td><a href="index.php?hinzufuegen=<?= htmlspecialchars($artikelId); ?>">In den Warenkorb</a></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
39
Kapitel_5/Lektion_4/warenkorb_loesung/warenkorb.php
Executable file
39
Kapitel_5/Lektion_4/warenkorb_loesung/warenkorb.php
Executable file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/_applikation.php';
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Warenkorb</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Ihr Warenkorb</h1>
|
||||
|
||||
<form action="warenkorb.php" method="post">
|
||||
<table>
|
||||
<tr>
|
||||
<th>Bezeichnung</th>
|
||||
<th>Anzahl</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Moderne Webseiten entwickeln</td>
|
||||
<td>
|
||||
<input type="text"
|
||||
name="artikel[1]"
|
||||
value="1"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<button type="submit" name="aktualisieren">Aktualisieren</button>
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<p><a href="index.php">Zur Produktauswahl</a></p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user