Source for file election_results.php
Documentation is available at election_results.php
require_once dirname (__FILE__ ) . '/../include/pear-config.php';
// Get the database class.
'portability' => DB_PORTABILITY_ALL ,
$dbh = & DB ::connect (PEAR_DATABASE_DSN , $options);
if (PEAR ::isError ($dbh)) {
die (" Failed to connect: $dsn\n" );
$dbh->setFetchMode (DB_FETCHMODE_ASSOC );
$toProcess = $dbh->getAll ('
FROM elections e LEFT JOIN election_results r on e.id = r.election_id
WHERE r.election_id IS NULL AND e.voteend < NOW()
foreach ($toProcess as $election) {
$totalabstain = $dbh->getOne ('
SELECT COUNT(*) FROM election_votes_abstain WHERE election_id=?
', array ($election['id']));
if ($election['maximum_choices'] == 1 ) {
$totalvotes = $dbh->getOne ('
SELECT COUNT(*) FROM election_votes_single WHERE election_id=?
', array ($election['id'])) + $totalabstain;
$results = $dbh->getAll ('
SELECT COUNT(*) as total, vote
FROM election_votes_single
', array ($election['id']), DB_FETCHMODE_ASSOC );
$totalvotes = $dbh->getOne ('
SELECT COUNT(*) FROM election_votes_multiple WHERE election_id=?
', array ($election['id'])) + $totalabstain;
$results = $dbh->getAll ('
SELECT COUNT(*) as total, vote
FROM election_votes_multiple
', array ($election['id']), DB_FETCHMODE_ASSOC );
foreach ($results as $vote) {
INSERT INTO election_results
(election_id, choice, votepercent, votetotal)
', array ($election['id'], $vote['vote'], $vote['total'] / $totalvotes,
Documentation generated on Mon, 11 Mar 2019 15:34:35 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|