您最多能選擇 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); |