Fix query + visualizzazione dati su pagina
This commit is contained in:
@@ -1,32 +1,53 @@
|
||||
<!-- RICHIESTA FILA A -->
|
||||
<?php
|
||||
session_start();
|
||||
include 'db_conf.php';
|
||||
|
||||
//Query per ottenere le statistiche dei dispositivi
|
||||
$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";
|
||||
// Query per ottenere il tempo totale di utilizzo giornaliero aggregato per fascia d'età
|
||||
$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);
|
||||
|
||||
// Interruzione in caso di errore nella richiesta
|
||||
if ($resultDispositivi === false){
|
||||
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>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<title>GenZ Digital Hub</title>
|
||||
</head>
|
||||
<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>
|
||||
</html>
|
||||
Reference in New Issue
Block a user