-
Notifications
You must be signed in to change notification settings - Fork 0
/
relatorio.php
57 lines (52 loc) · 1.65 KB
/
relatorio.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Relatório</title>
</head>
<body>
<?php
require 'config.php';
$lista = [];
$sql = $pdo->query("SELECT * FROM votos");
if ($sql->rowCount() > 0) {
$lista = $sql->fetchAll(PDO::FETCH_ASSOC);
}
?>
<h1>Relatório de Votos</h1>
<table border="1" width="70%">
<tr>
<th>Nome da Chapa</th>
<th>Quantia de Votos</th>
<th>Percentual</th>
</tr>
<?php
$sql = $pdo->query("SELECT voto, COUNT(*) AS total_votos FROM votos GROUP BY voto");
$resultados = $sql->fetchAll(PDO::FETCH_ASSOC);
$sql = $pdo->query("SELECT * FROM votos");
$somatorio_final = $sql->rowCount()
?>
<?php foreach($resultados as $resultado): ?>
<tr>
<td><?= $resultado['voto'] ?></td>
<td><?= $resultado['total_votos'] ?></td>
<td>
<?php
$percentual = ($resultado['total_votos'] / $somatorio_final) * 100;
$formatado = number_format($percentual, 2) ."%";
echo $formatado;
?>
</td>
</tr>
<?php endforeach; ?>
<tr>
<td><strong>TOTAL</strong></td>
<td><?= "<strong>$somatorio_final</strong>" ?></td>
<td><strong>100%</strong></td>
</tr>
</table>
<a href="votacao.php">Voltar para Votação</a>
</body>
</html>