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.

getresults.php 580B

12345678910111213141516171819202122232425
  1. <?php
  2. require_once __DIR__ . "/required.php";
  3. $qid = $VARS['qid'];
  4. if (!$database->has('questions', ['qid' => $qid])) {
  5. die();
  6. }
  7. $total = $database->count('responses', ['qid' => $qid]);
  8. $answers = $database->select('answers', ['aid', 'atext'], ['qid' => $qid]);
  9. $data['total'] = $total;
  10. $data['answers'] = [];
  11. foreach ($answers as $a) {
  12. $votes = $database->count('responses', ['aid' => $a['aid']]);
  13. $data['answers'][] = [
  14. "id" => $a['aid'],
  15. "votes" => $votes,
  16. "percent" => ($votes / $total) * 100.0 . "%"
  17. ];
  18. }
  19. echo json_encode($data);