Transizione da tabella a griglia prodotti

This commit is contained in:
2026-03-25 10:51:13 +01:00
parent f357d509a8
commit 457c933089

View File

@@ -2,7 +2,7 @@
include 'db_conf.php'; include 'db_conf.php';
// Query per ottenere tutti i prodotti // Query per ottenere tutti i prodotti
$sql = "SELECT p.ProductID, p.ProductName, c.Name AS 'CategoryName', p.Description, p.Price, p.StockQuantity FROM Products p JOIN Categories c ON p.CategoryID=c.CategoryID"; $sql = "SELECT p.ProductID, p.ProductName, c.Name AS 'CategoryName', p.Description, p.Price, p.StockQuantity, p.ImagePath FROM Products p JOIN Categories c ON p.CategoryID=c.CategoryID";
$result = $conn->query($sql); $result = $conn->query($sql);
if ($result === false) { if ($result === false) {
@@ -17,17 +17,43 @@ if ($result === false) {
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TechStore - Prodotti</title> <title>TechStore - Prodotti</title>
<style> <style>
table { .products-grid {
border-collapse: collapse; display: grid;
width: 100%; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 20px;
padding: 20px;
} }
th, td { .product-card {
border: 1px solid #ddd; border: 1px solid #ddd;
padding: 8px; border-radius: 8px;
text-align: left; padding: 16px;
text-align: center;
background-color: #fff;
} }
th { .product-card img {
background-color: #f2f2f2; max-width: 100%;
height: auto;
margin-bottom: 10px;
}
.product-card h3 {
margin: 10px 0;
font-size: 18px;
}
.product-card p {
margin: 5px 0;
color: #666;
}
.product-card button {
padding: 8px 16px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
}
.product-card button:hover {
background-color: #0056b3;
} }
</style> </style>
</head> </head>
@@ -42,28 +68,16 @@ if ($result === false) {
<h1>Prodotti TechStore</h1> <h1>Prodotti TechStore</h1>
<?php if ($result->num_rows > 0): ?> <?php if ($result->num_rows > 0): ?>
<table> <div class="products-grid">
<thead> <?php while ($row = $result->fetch_assoc()): ?>
<tr> <div class="product-card">
<?php <img src="img/<?php echo htmlspecialchars($row['ImagePath']); ?>" alt="Immagine prodotto">
// Ottieni i nomi delle colonne <h3><?php echo htmlspecialchars($row['ProductName']); ?></h3>
$fields = $result->fetch_fields(); <p><?php echo htmlspecialchars($row['Price']); ?>€</p>
foreach ($fields as $field) { <button>Aggiungi al carrello</button>
echo "<th>" . htmlspecialchars($field->name) . "</th>"; </div>
} <?php endwhile; ?>
?> </div>
</tr>
</thead>
<tbody>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<?php foreach ($row as $value): ?>
<td><?php echo htmlspecialchars($value); ?></td>
<?php endforeach; ?>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php else: ?> <?php else: ?>
<p>Nessun prodotto trovato.</p> <p>Nessun prodotto trovato.</p>
<?php endif; ?> <?php endif; ?>