12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?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("maxselect", $poll['maxselect']);
- $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)){
- $row['choice'] = urldecode($row['choice']);
- $poll_options[] = $row;
- }
- $smarty->assign("poll_options", $poll_options);
- // get poll results
- $query = "SELECT name, choice, other 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'];
- $other = urldecode($row['other']);
-
- $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['other'] = $other;
- $res['choice'] = $choice;
- $results[] = $res;
- }
- if (isset($results))
- $smarty->assign('results', $results);
- $smarty->assign('totals', $totals);
- $smarty->display ("poll.html");
- ?>
|