<?php
$db = mysqli_connect('localhost', 'root', '', 'opony');

header("Refresh: 10");
?>
<!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>OPONY</title>
    <link rel="stylesheet" href="styl.css">
</head>
<body>
<div id="main">
    <div id="side-block">
        <?php
        $sql1 = "SELECT * FROM opony ORDER BY cena LIMIT 10;";
        $result1 = mysqli_query($db, $sql1);

        while ($row = mysqli_fetch_assoc($result1)) {
            echo "<div class='opona'>";
            if ($row['sezon'] == 'letnia') {
                echo "<img src='lato.png' alt='letnia'>";
            } elseif ($row['sezon'] == 'zimowa') {
                echo "<img src='zima.png' alt='zimowa'>";
            } elseif ($row['sezon'] == 'uniwersalna') {
                echo "<img src='uniwer.png' alt='uniwersalna'>";
            }
            echo "<h4>Opona: {$row['producent']} {$row['model']}</h4>";
            echo "<h3>Cena: {$row['cena']}</h3>";
            echo "</div>";
        }
        ?>
        <p><a href="https://opona.pl">więcej ofert</a></p>
    </div>
    <div id="sections">
        <section id="section-1">
            <img src="opona.png" alt="Opona">
            <h2>Opona dnia</h2>
            <?php
            $sql2 = "SELECT producent, model, sezon, cena FROM opony WHERE nr_kat = 9;";
            $result2 = mysqli_query($db, $sql2);

            while ($row = mysqli_fetch_assoc($result2)) {
                echo "<h2>{$row['producent']} model {$row['model']}</h2>";
                echo "<h2>Sezon: {$row['sezon']}</h2>";
                echo "<h2>Tylko {$row['cena']} zł!</h2>";
            }
            ?>
        </section>
        <section id="section-2">
            <h2>Najnowsze zamówienie</h2>
            <?php
            $sql3 = "SELECT id_zam, ilosc, model, cena FROM zamowienie JOIN opony USING(nr_kat) ORDER BY RAND() LIMIT 1;";
            $result3 = mysqli_query($db, $sql3);

            while ($row = mysqli_fetch_assoc($result3)) {
                $wartosc = $row['ilosc'] * $row['cena'];
                echo "<h2>{$row['id_zam']}{$row['ilosc']} sztuki modelu {$row['model']}</h2>";
                echo "<h2>Wartość zamówienia {$wartosc} zł</h2>";
            }
            ?>
        </section>
    </div>
</div>
<footer><p>Stronę wykonał: Jakub Grzegorczyk 3p</p></footer>
</body>
</html>
<?php
mysqli_close($db);
?>