| Newsgroups |
php.notes |
| Message-ID |
<[email protected]> |
<?php
session_start();
// Datenbankverbindung etablieren
$servername = "mysql";
$username = "root";
$password = "htlkrems";
try {
// Instanz des PDO Objektes erzeugen
$conn = new PDO("mysql:host=$servername;dbname=classicmodels", $username, $password);
// PDO Error Mode auf Exception setzen
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//echo "Connected successfully"; // Ausgabe wenn DB-Verbindung ok
} catch(PDOException $e) {
// Ausgabe der Fehlermeldung falls DB-Verbindung fehlgeschlagen
echo "Connection failed: " . $e->getMessage();
}
$stmt = $conn->query("SELECT * FROM products");
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Products</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
<div class="container">
<!-- STEP 2: Ausgabe in einer HTML-Tabelle -->
<h3>Alle Beiträge:</h3>
<form action="index.php" method="get">
<table class="table table-striped">
<thead>
<tr>
<th><a style="text-decoration: none; color: black" href="?productName">Product Name</a></th>
<th><a style="text-decoration: none; color: black" href="?scale">Scale</a></th>
<th><a style="text-decoration: none; color: black" href="?stock">Stock</a></th>
<th><a style="text-decoration: none; color: black" href="?price">Price</a></th>
<th></th>
<th></th>
<th><a style="text-decoration: none; color: black" href="?comments">Comments</a></th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $row) {
// Iteration über alle Datensätze -> Ergebnis ist ein 1-dimensionales assoziatives Array
// print_r($result); // Ausgabe des Arrays zu Testzwecken
echo "<tr>";
// Werte in einer Table-row ausgeben
echo "<td>" . $row['productName'] . "</td>";
echo "<td>" . $row['productScale'] . "</td>";
echo "<td>" . $row['quantityInStock'] . "</td>";
echo "<td>" . $row['buyPrice'] . "</td>";
// STEP 3: Link per mit GET auf einzelnen Datensatz
echo "<td><a href='?id=" . $row['productCode'] . "'>Löschen</a></td>";
echo "<td><input type='checkbox' name='del[]' value='" . $row['productCode'] . "'></td>";
echo "<td><a style='text-decoration: none; color: black' href='comments.php'>,(=)</a></td>";
echo "</tr>";
}
?>
</tbody>
</table>
</form>
</div>
</body>
</html>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 91.113.31.198)
----
Manual Page -- https://php.net/manual/en/configuration.php
Edit -- https://main.php.net/note/edit/130191
Del: integrated -- https://main.php.net/note/delete/130191/integrated
Del: useless -- https://main.php.net/note/delete/130191/useless
Del: bad code -- https://main.php.net/note/delete/130191/bad+code
Del: spam -- https://main.php.net/note/delete/130191/spam
Del: non-english -- https://main.php.net/note/delete/130191/non-english
Del: in docs -- https://main.php.net/note/delete/130191/in+docs
Del: other reasons-- https://main.php.net/note/delete/130191
Reject -- https://main.php.net/note/reject/130191
Search -- https://main.php.net/manage/user-notes.php