Make `preflight` request pass okay
[asis23-votoe-server.git] / get_report.php
blob237a42299a604aecfb37c39f5e7632fde00f33f7
1 <?php
3 function handle_request($id, $input) {
4 $list = [];
6 $db = new SQLite3('database.sqlite');
7 $query1 = $db->query("SELECT * FROM candidatos");
9 while ($candidate = $query1->fetchArray(SQLITE3_ASSOC)) {
10 $id = $candidate['id'];
11 $votes = 0;
13 $query2 = $db->query("SELECT * FROM votos where candidato_id = {$id}");
15 while ($vote = $query2->fetchArray(SQLITE3_ASSOC)) {
16 ++$votes;
19 $list[] = [
20 'id' => $id,
21 'name' => $candidate['nombre'],
22 'votes' => $votes,
26 $db->close();
28 echo json_encode($list);