This repository has been archived on 2026-06-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
sgd/ysql7-kap2/kurs.class.php
T

132 lines
3.7 KiB
PHP

<?php
class Kurs {
private $tabelle = "kurs";
public function loeschen($id) {
require("db.inc.php");
$sql = "DELETE FROM " .$this->tabelle ." WHERE kursnr = :kursnr";
if ($stmt = $pdo -> prepare($sql)) {
$stmt->bindParam(':kursnr', $id);
$stmt -> execute();
}
}
public function anlegen($felder) {
require("db.inc.php");
$kursnr = NULL;
$ressort = $felder["ressort"];
$titel = $felder["titel"];
$beschreibung = $felder["beschreibung"];
$preis = $felder["preis"];
$sql = "INSERT INTO " .$this->tabelle ." (kursnr,
ressort,
titel,
beschreibung,
preis)
VALUES (:kursnr, :ressort, :titel, :beschreibung, :preis)";
if ($stmt = $pdo -> prepare($sql)) {
$param= array(':kursnr' => $kursnr,
':ressort' => $ressort,
':titel' => $titel,
':beschreibung' => $beschreibung,
':preis' => $preis);
if($stmt -> execute($param)) {
echo "<h2>Datensatz erfolgreich gespeichert!</h2>\n";
}
else {
echo "<h2>Fehler beim Speichern!</h2>\n";
}
}
}
public function bearbeiten($felder) {
require("db.inc.php");
$kursnr = $felder["mode"];
$ressort = $felder["ressort"];
$titel = $felder["titel"];
$beschreibung = $felder["beschreibung"];
$preis = $felder["preis"];
$sql = "UPDATE " .$this->tabelle ." SET
ressort = :ressort,
titel = :titel,
beschreibung = :beschreibung,
preis = :preis
WHERE kursnr = :kursnr";
if ($stmt = $pdo -> prepare($sql)) {
$param= array(':kursnr' => $kursnr,
':ressort' => $ressort,
':titel' => $titel,
':beschreibung' => $beschreibung,
':preis' => $preis);
if($stmt -> execute($param)) {
echo "<h2>Datensatz erfolgreich gespeichert!</h2>\n";
}
else {
echo "<h2>Fehler beim Speichern!</h2>\n";
}
}
}
public function lesenDatensatz($id) {
require("db.inc.php");
if ($stmt = $pdo -> prepare("SELECT ressort, titel, beschreibung, preis FROM " .$this->tabelle ." WHERE kursnr=:kursnr")) {
$stmt->bindParam(':kursnr',$id);
$stmt -> execute();
return($stmt->fetch(PDO::FETCH_ASSOC));
}
else {
return false;
}
}
public function lesenAlleDaten() {
require_once("db.inc.php");
if ($stmt = $pdo -> prepare("SELECT kursnr, ressort, titel, beschreibung, preis FROM " .$this->tabelle ." ORDER BY ressort, titel")) {
$stmt -> execute();
echo "<table id=\"zebra\">\n\t";
echo "<thead><tr><th>Nummer</th><th>Ressort</th><th>Titel</th><th>Beschreibung</th><th>Preis</th><th>Bearbeiten</th></tr></thead>";
echo "<tbody>\n\t";
$count = 0;
while ($z = $stmt -> fetch()) {
$count+= 1;
$zebratyp = "ungerade";
echo "<tr ";
if($count % 2 == 0) {
$zebratyp = "gerade";
}
echo "class=\"" .$zebratyp
."\">\n\t<td>"
. htmlspecialchars($z['kursnr'])
."</td>\n\t<td>"
. htmlspecialchars($z['ressort'])
."</td>\n\t<td>"
. htmlspecialchars($z['titel'])
."</td>\n\t<td>"
. htmlspecialchars($z['beschreibung'])
."</td>\n\t<td>"
. htmlspecialchars($z['preis'])
."</td>\n\t<td>"
."<a href=\"kbearbeiten.php?kursnr=" .htmlspecialchars($z['kursnr']) ."\">bearbeiten</a>"
."</td>\n</tr>";
}
echo "</tbody>\n</table>\n";
}
}
}
?>