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:
76
index.php
76
index.php
@@ -2,7 +2,7 @@
|
||||
include 'db_conf.php';
|
||||
|
||||
// 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);
|
||||
|
||||
if ($result === false) {
|
||||
@@ -17,17 +17,43 @@ if ($result === false) {
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>TechStore - Prodotti</title>
|
||||
<style>
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
.products-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
||||
gap: 20px;
|
||||
padding: 20px;
|
||||
}
|
||||
th, td {
|
||||
.product-card {
|
||||
border: 1px solid #ddd;
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
text-align: center;
|
||||
background-color: #fff;
|
||||
}
|
||||
th {
|
||||
background-color: #f2f2f2;
|
||||
.product-card img {
|
||||
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>
|
||||
</head>
|
||||
@@ -42,28 +68,16 @@ if ($result === false) {
|
||||
<h1>Prodotti TechStore</h1>
|
||||
|
||||
<?php if ($result->num_rows > 0): ?>
|
||||
<table>
|
||||
<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()): ?>
|
||||
<tr>
|
||||
<?php foreach ($row as $value): ?>
|
||||
<td><?php echo htmlspecialchars($value); ?></td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
<?php endwhile; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="products-grid">
|
||||
<?php while ($row = $result->fetch_assoc()): ?>
|
||||
<div class="product-card">
|
||||
<img src="img/<?php echo htmlspecialchars($row['ImagePath']); ?>" alt="Immagine prodotto">
|
||||
<h3><?php echo htmlspecialchars($row['ProductName']); ?></h3>
|
||||
<p><?php echo htmlspecialchars($row['Price']); ?>€</p>
|
||||
<button>Aggiungi al carrello</button>
|
||||
</div>
|
||||
<?php endwhile; ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<p>Nessun prodotto trovato.</p>
|
||||
<?php endif; ?>
|
||||
|
||||
Reference in New Issue
Block a user