Pakitulungan naman po ako. Number 1 letter B and C po sana. Thank you!
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.
<table style="border: 1px solid black;">
<thead >
<tr>
<th>Precint</th>
<th>Candidate A</th>
<th>Candidate B</th>
<th>Candidate C</th>
<th>Candidate D</th>
</tr>
</thead>
<tbody>
<?php
$results = array (
array(192,147,186,114,267),
array(48,90,12,21,13),
array(206,312,121,408,382),
array(37,21,38,39,29),
);
for ($col = 0; $col < 5; $col++) {
echo "<tr><td>" . $col+1 . "</td>";
for ($row = 0; $row < 4; $row++) {
echo "<td>" . $results[$row][$col] . "</td> ";
}
echo "</tr>";
}
?>
</tbody>
</table>
<br>
<table style="border: 1px solid black;">
<thead>
<tr>
<th>Candidate</th>
<th>Total</th>
<th>Percentage</th>
</tr>
</thead>
<tbody>
<?php
$totalCandidates = count($results);
$candidates = array("A","B","C","D");
$total = array();
$percentage = array();
$winner = null;
for ($i=0; $i < $totalCandidates; $i++) {
$total[$i] = array_sum($results[$i]);
}
$grandTotal = array_sum($total);
for ($i=0; $i < $totalCandidates; $i++) {
$percentage[$i] = round($total[$i] / $grandTotal * 100);
echo "<tr><td>" . $candidates[$i] . "</td>";
echo "<td>" . $total[$i] . "</td>";
echo "<td>" . $percentage[$i] . "%</td></tr>";
if ($percentage[$i] > 50 )
$winner = $i;
}
?>
</tbody>
</table>
<?php
echo "<br>" . "Candidate " . $candidates[$winner] . " with the " . $percentage[$winner] . "% total votes is the winner.";
?>