<?php
require_once('../../includes/functions.php');
checkSession();

try {
    $connection = getDbConnection();
    $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $tipologia = $_GET["tipologia"];
    $prepare = $connection->prepare("SELECT t.nome
                                                FROM modello AS m
                                                INNER JOIN biciclette.tipologia t on m.tipologia = t.codice
                                                WHERE m.tipologia = ?
                                                ORDER BY t.codice");

    $prepare->bindParam(1, $tipologia);
    $prepare->execute();

    if ($prepare->rowCount() >= 1) {
        $bici = $prepare->fetchAll();
        $quantita = $prepare->rowCount();
        $tipologia = $bici[0]['nome'];
    } else {
        echo "nessuna quantita";
    }

} catch (PDOException $e) {
    die("Error: " . $e->getMessage());
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login</title>
    <link rel="stylesheet" href="../../includes/css/pico.min.css">
</head>
<body>
    <main class="container">
        <a href="../dashboard.php" class="button">Torna alla dashboard</a>

        <h1>Quantita per tipologia: <?php echo $tipologia ?></h1>
        <h1><?= $quantita ?></h1>
    </main>
</body>
</html>
