Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Ne petku ne, ja jsem v tom nevinne :(</title>
- </head>
- <body>
- <?php
- require_once 'trida.php';
- $trida = new trida();
- $skoly = $trida->selectAll();
- foreach ($skoly as $skola) {
- echo "<p>Nazev skoly: " . $skola['nazev'] . "<a href='detail.php?id=" . $skola['id'] . "'>Detail</a></p>";
- }
- ?>
- </body>
- </html>
- -------------------- TŘÍDA
- <?php
- class trida {
- function __construct() {}
- function selectAll() {
- $ukazVse = $this->connect()->prepare("SELECT * FROM `skoly`");
- $ukazVse->execute();
- return $ukazVse->fetchAll(PDO::FETCH_ASSOC);
- }
- function selectOne($id) {
- $ukazJeden = $this->connect()->prepare("SELECT * FROM `skoly` WHERE `id` = " . $id . "");
- $ukazJeden->execute();
- return $ukazJeden->fetchAll(PDO::FETCH_ASSOC);
- }
- function connect() {
- $dsn = "mysql:dbname=skola;host=localhost";
- $user = "root";
- $password = "";
- $conn = new PDO($dsn, $user, $password);
- return $conn;
- }
- }
- -------------------- DETAIL
- <?php
- require_once 'trida.php';
- $trida = new trida();
- if (isset($_GET["id"])) {
- $id = $_GET["id"];
- $sk = $trida->selectOne($id);
- foreach ($sk as $s) {
- if ($s["typ"] = "z") {
- $typ = "zakladni skola";
- } else if ($s["typ"] = "s") {
- $typ = "stredni skola";
- } else if ($s["typ"] = "v") {
- $typ = "vysoka skola";
- }
- echo "<p>Nazev skoly: " . $s['nazev'] . " Typ skoly: " . $typ . " Pocet zaku: " . $s['pocetZaku'] . "</p>";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement