25'ten fazla konu seçemezsiniz
Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
25 satır
580 B
PHP
25 satır
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); |