<?php
$db = mysqli_connect("localhost", "root", "", "hodowla");
?>
    <!doctype html>
    <html lang="pl">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Hodowla świnek morskich</title>
        <link rel="stylesheet" href="styl.css">
    </head>
    <body>
    <header>
        <h1>Hodowla świnek morskich - zamów świnkowe maluszki</h1>
    </header>
    <nav>
        <a href="peruwianka.php">Rasa Peruwianka</a>
        <a href="american.php">Rasa American</a>
        <a href="crested.php">Rasa Crested</a>
    </nav>
    <aside>
        <h3>Poznaj wszystkie rasy świnek morskich</h3>
        <ol>
            <?php
            $sql1 = "SELECT rasa FROM rasy;";
            $result1 = mysqli_query($db, $sql1);
            while ($row = mysqli_fetch_assoc($result1)) {
                echo "<li>{$row['rasa']}</li>";
            }
            ?>
        </ol>
    </aside>
    <main>
        <img src="american.jpg" alt="Świnka morska rasy american">
        <?php
        $sql2 = "SELECT DISTINCT data_ur, miot, rasa FROM swinki JOIN rasy ON rasy.id = rasy_id WHERE rasy_id = 6;";
        $result2 = mysqli_query($db, $sql2);
        while ($row = mysqli_fetch_assoc($result2)) {
            echo "<h2>Rasa - {$row['rasa']}</h2>";
            echo "<p>Data urodzenia: {$row['data_ur']}</p>";
            echo "<p>Oznaczenie miotu: {$row['miot']}";
        }
        ?>
        <hr>
        <h2>Świnki w tym miocie</h2>
        <?php
        $sql3 = "SELECT imie, cena, opis FROM swinki WHERE rasy_id = 6;";
        $result3 = mysqli_query($db, $sql3);
        while ($row = mysqli_fetch_assoc($result3)) {
            echo "<h3>{$row['imie']} - {$row['cena']}</h3>";
            echo "<p>{$row['opis']}</p>";
        }
        ?>
    </main>

    <footer>
        <p>Stronę wykonał: Jakub Grzegorczyk 3p/1</p>
    </footer>
    </body>
    </html>
<?php
mysqli_close($db);
