Hi there,
I have inherited a site, and am not very good with PHP so please forgive me!
It's a simpel voting system, where people vote for A B or C.
I have the following php on a page, which looks in a table, pulls the 'total' for each row (vote) and displays then on a page so we can see how many votes were given to A, B or C.
<?php
$stmt = $modx->prepare("SELECT * FROM `modx_ltda_vote` ORDER BY `option` ASC");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$output = [];
foreach ($rows as $row) {
$output[] = $row['option'] . ' has ' . $row['total'] . ' votes';
}
return implode('<br><br>', $output);
So the ooutut is currently:
A has 10 votes
B has 30 votes
C has 40 votes
I would like to be able to put a percentage next to each number of 'votes' - so that the user can see the percentage of all the votes so far.
e.g.
A has 10 votes (12.5%).
B has 30 votes (37.5%).
C has 40 votes (50%).
I hope the above makes sense!
Thanks in advance for a steer in the rirght direction - I just don't know PHP well enough to work out the syntax etc.