Du kannst nicht mehr als 25 Themen auswählen
Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
25 Zeilen
580 B
PHP
25 Zeilen
580 B
PHP
<?php
|
|
|
|
require_once __DIR__ . "/required.php";
|
|
|
|
$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 . "%"
|
|
];
|
|
}
|
|
|
|
echo json_encode($data); |