-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.php
90 lines (75 loc) · 3.52 KB
/
result.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
include('header.php');
?>
<br>
<div class="container-fluid mt-2" style="width: 70%;">
<div class="row">
<div class="col-12">
<?php
// Include your database connection file
include('connection.php');
// Fetch candidates data from the database (replace with your actual column names)
$candidatesQuery = "SELECT c.CandidateID, c.CandidateName, c.Symbol, COUNT(v.VID) as Votes
FROM candidates c
LEFT JOIN votes v ON c.CandidateID = v.CandidateID
WHERE c.SectionBatch = '" . $_GET['SectionBatch'] . "'
GROUP BY c.CandidateID
ORDER BY Votes DESC";
$candidatesResult = mysqli_query($conn, $candidatesQuery);
if (!$candidatesResult) {
echo "Error: " . $candidatesQuery . "<br>" . mysqli_error($conn);
exit();
}
// Fetch total number of voters
$totalVotersQuery = "SELECT COUNT(DISTINCT VID) as TotalVoters FROM votes";
$totalVotersResult = mysqli_query($conn, $totalVotersQuery);
if (!$totalVotersResult) {
echo "Error: " . $totalVotersQuery . "<br>" . mysqli_error($conn);
exit();
}
$rowTotalVoters = mysqli_fetch_assoc($totalVotersResult);
$totalVoters = $rowTotalVoters['TotalVoters'];
?>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<h3 class="text-center m-4">Result for <?php echo $_GET['SectionBatch']; ?></h3>
<table class="table table-bordered table-hover">
<thead class="table-success">
<tr>
<th class="text-center">Rank</th>
<th class="text-center">Candidate Name</th>
<th class="text-center">Candidate ID</th>
<th class="text-center">Symbol</th>
<th class="text-center">No. of Votes / No. of Voters</th>
</tr>
</thead>
<tbody>
<?php
$rank = 1;
while ($row = mysqli_fetch_assoc($candidatesResult)) {
echo '<tr>';
echo '<th class="text-center" scope="row"># ' . $rank . '.</th>';
echo '<td class="text-center">' . $row['CandidateName'] . '</td>';
echo '<td class="text-center">' . $row['CandidateID'] . '</td>';
echo '<td class="fs-5 text-center">' . $row['Symbol'] . '</td>';
echo '<td class="text-center">' . $row['Votes'] . ' votes out of ' . $totalVoters . ' voters</td>';
echo '</tr>';
$rank++;
}
?>
</tbody>
</table>
</div>
</div>
</div>
<?php
// Close the database connection
mysqli_close($conn);
?>
</div>
</div>
</div>
<?php
include('footer.php');
?>