prepare("SELECT * FROM categories WHERE id = ?"); $stmt->execute([$id]); $cat = $stmt->fetch(); if (!$cat) { header("Location: index.php"); exit; } // Fetch products for this category $stmt = db()->prepare("SELECT p.*, c.name as category_name FROM products p JOIN categories c ON p.category_id = c.id WHERE p.category_id = ? ORDER BY p.id DESC"); $stmt->execute([$id]); $cat_products = $stmt->fetchAll(); ?>