您最多选择25个主题
主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
25 行
580 B
PHP
25 行
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); |