This repository was archived by the owner on Nov 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoll.php
More file actions
50 lines (39 loc) · 1.21 KB
/
Copy pathpoll.php
File metadata and controls
50 lines (39 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
require_once("./common.php");
$poll_id = $_GET['poll_id'];
// get poll metadata
$query = "SELECT * FROM polls WHERE id = $poll_id";
$result = mysql_query($query);
$poll = mysql_fetch_array($result);
$smarty->assign("title", $poll['title']);
$smarty->assign("description", $poll['description']);
$smarty->assign("poll_id", $poll_id);
// get poll options
$query = "SELECT choice, value FROM poll_options WHERE poll_id = $poll_id";
$result = mysql_query($query);
$num_options = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)){
$poll_options[] = $row;
}
$smarty->assign("poll_options", $poll_options);
// get poll results
$query = "SELECT name, choice FROM results WHERE poll_id = $poll_id";
$result = mysql_query($query);
$totals = array_pad(array(), $num_options, 0);
while ($row = mysql_fetch_assoc($result)){
$name = $row['name'];
$value = $row['choice'];
unset($choice);
for ($i = 0; $i < $num_options ; $i++){
if ($choice[$i] = (bool) ($value & (1<<$i)))
$totals[$i]++;;
}
$res['name'] = $name;
$res['choice'] = $choice;
$results[] = $res;
}
if (isset($results))
$smarty->assign('results', $results);
$smarty->assign('totals', $totals);
$smarty->display ("poll.html");
?>