Files
techstore/index.php

74 lines
2.3 KiB
PHP

<?php
include 'db_conf.php';
// Query per ottenere tutti i prodotti
$sql = "SELECT * FROM Products";
$result = $conn->query($sql);
if ($result === false) {
die("Errore nella query: " . $conn->error);
}
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TechStore - Prodotti</title>
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<header style="display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #f2f2f2; border-bottom: 1px solid #ddd;">
<div id="logo" style="font-size: 24px; font-weight: bold;">TechStore</div>
<div>
<button style="margin-left: 10px; padding: 8px 16px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer;">Carrello</button>
<button style="margin-left: 10px; padding: 8px 16px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">Accesso</button>
</div>
</header>
<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>
<?php else: ?>
<p>Nessun prodotto trovato.</p>
<?php endif; ?>
<?php $conn->close(); ?>
</body>
</html>