<?php
$host = 'localhost';
$dbname = 'devrbdrinks_rcup';
$username = 'devrbdri_root';
$password = 'vinny.1994'; // Add your password if needed

unset($sql);
unset($products);

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    die("Could not connect to the database: " . $e->getMessage());
}

$offset = isset($_GET['offset']) ? (int)$_GET['offset'] : 0;
$limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 8;

$sql = "SELECT * FROM products WHERE brand_id = 1 AND inactive = 0 ORDER BY p_order ASC LIMIT :offset, :limit";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
$stmt->execute();

$products = $stmt->fetchAll(PDO::FETCH_ASSOC);

foreach ($products as $product) {
    echo '<div class="product" data-hover-image="' . htmlspecialchars($product['hover_image_url']) . '">';
    echo '<img src="' . htmlspecialchars($product['image_url']) . '" alt="' . htmlspecialchars($product['name']) . '">';
    echo '<h2>' . htmlspecialchars($product['name']) . '</h2>';
    echo '<p>' . htmlspecialchars($product['description']) . '</p>';
    echo '</div>';
}
?>