Compare commits

...

2 Commits

Author SHA1 Message Date
AndreStork 461a1f4853 Fix query + visualizzazione dati su pagina 2026-04-17 11:25:58 +02:00
AndreStork 1ee47f62e6 Fix query SQL non funzionanti in index 2026-04-17 11:10:28 +02:00
+33 -12
View File
@@ -1,32 +1,53 @@
<!-- RICHIESTA FILA A -->
<?php <?php
session_start(); session_start();
include 'db_conf.php'; include 'db_conf.php';
//Query per ottenere le statistiche dei dispositivi // Query per ottenere il tempo totale di utilizzo giornaliero aggregato per fascia d'età
$sql = "SELECT s.id_stat_device, f.range_eta, s.tipo_dispositivo, s.ore_medie_giornaliere FROM statistiche_dispositivi s JOIN fasce_eta f ON f.id_fascia=s.id_fascia"; $sql = "SELECT f.range_eta, SUM(s.ore_medie_giornaliere) AS ore_totali
FROM Statistiche_Dispositivi s
JOIN Fasce_Eta f ON f.id_fascia=s.id_fascia
GROUP BY f.id_fascia, f.range_eta
ORDER BY f.id_fascia ASC";
$resultDispositivi = $conn->query($sql); $resultDispositivi = $conn->query($sql);
// Interruzione in caso di errore nella richiesta // Interruzione in caso di errore nella richiesta
if ($resultDispositivi === false){ if ($resultDispositivi === false){
die("Errore nella query: " . $conn->error); die("Errore nella query: " . $conn->error);
} }
//Query per ottenere le statistiche social
$sql = "SELECT s.id_stat_social, f.range_eta, s.piattaforma, s.minuti_medi_giornalieri, s.percentuale_penetrazione FROM statistiche_social s JOIN fasce_eta f ON f.id_fascia = s.id_fascia";
$resultSocial = $conn->query($sql);
// Interruzione in caso di errore nella richiesta
if ($resultSocial === false){
die("Errore nella query: " . $conn->error);
}
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title> <title>GenZ Digital Hub</title>
</head> </head>
<body> <body>
<?php if (isset($_SESSION['id'])): ?>
<h1>Benvenuto, <?php echo htmlspecialchars($_SESSION['name'] . ' ' . $_SESSION['surname']); ?>!</h1>
<p><a href="logout.php">Logout</a></p>
<h2>Tempo Totale di Utilizzo Giornaliero per Fascia d'Età</h2>
<table border="1" cellpadding="10" cellspacing="0">
<thead>
<tr>
<th>Fascia d'Età</th>
<th>Ore Totali Giornaliere</th>
</tr>
</thead>
<tbody>
<?php while ($row = $resultDispositivi->fetch_assoc()): ?>
<tr>
<td><?php echo htmlspecialchars($row['range_eta']); ?></td>
<td><?php echo number_format($row['ore_totali'], 2, ',', '.'); ?> ore</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php else: ?>
<h1>Benvenuto su GenZ Digital Hub</h1>
<p><a href="login.php">Accedi</a> o <a href="register.php">Registrati</a> per visualizzare le statistiche.</p>
<?php endif; ?>
</body> </body>
</html> </html>