mirror of
https://codeberg.org/ThisIsMiseryy/techstore
synced 2026-03-29 20:21:20 +00:00
Transizione da tabella a griglia prodotti
This commit is contained in:
72
index.php
72
index.php
@@ -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>
|
|
||||||
<tr>
|
|
||||||
<?php
|
|
||||||
// Ottieni i nomi delle colonne
|
|
||||||
$fields = $result->fetch_fields();
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
echo "<th>" . htmlspecialchars($field->name) . "</th>";
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<?php while ($row = $result->fetch_assoc()): ?>
|
<?php while ($row = $result->fetch_assoc()): ?>
|
||||||
<tr>
|
<div class="product-card">
|
||||||
<?php foreach ($row as $value): ?>
|
<img src="img/<?php echo htmlspecialchars($row['ImagePath']); ?>" alt="Immagine prodotto">
|
||||||
<td><?php echo htmlspecialchars($value); ?></td>
|
<h3><?php echo htmlspecialchars($row['ProductName']); ?></h3>
|
||||||
<?php endforeach; ?>
|
<p><?php echo htmlspecialchars($row['Price']); ?>€</p>
|
||||||
</tr>
|
<button>Aggiungi al carrello</button>
|
||||||
|
</div>
|
||||||
<?php endwhile; ?>
|
<?php endwhile; ?>
|
||||||
</tbody>
|
</div>
|
||||||
</table>
|
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<p>Nessun prodotto trovato.</p>
|
<p>Nessun prodotto trovato.</p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|||||||
Reference in New Issue
Block a user