A simple system for creating multiple-choice questions for an audience to answer on their phones. Responses are tallied and displayed in real-time. https://openquestion.netsyms.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

39 lines
922 B

<?php
require_once __DIR__ . "/required.php";
header('Content-Type: application/json');
$qid = $VARS['qid'];
if (!$database->has('questions', ['qid' => $qid])) {
die();
}
$total = $database->count('responses', ['qid' => $qid]);
$answers = $database->select('answers', ['aid', 'atext'], ['qid' => $qid]);
$data['total'] = $total;
$data['answers'] = [];
foreach ($answers as $a) {
$votes = $database->count('responses', ['aid' => $a['aid']]);
$data['answers'][] = [
"id" => $a['aid'],
"votes" => $votes,
"percent" => ($votes / $total) * 100.0 . "%"
];
}
$responses = $database->select('responses', ['name', 'aid'], ['qid' => $qid]);
$data['responses'] = [];
foreach ($responses as $r) {
if ($r['name'] == null) {
$r['name'] = "Anonymous";
}
$data['responses'][] = [
"name" => $r['name'],
"aid" => $r['aid']
];
}
echo json_encode($data);