Tmx |
17th December 2010 16:02 |
Problem with poll
Hi, i have small problem with poll
I can't vote in poll.... when i vote it not show a result!
and there is my poll.php
Code:
if (!defined('BLOCK_FILE')) {
Header("Location: ../index.php");
exit;
}
global $CURUSER, $tracker_lang, $ss_uri;
// Get current poll
$res = sql_query("SELECT * FROM polls ORDER BY added DESC LIMIT 1") or sqlerr(__FILE__, __LINE__);
if($pollok=(mysql_num_rows($res))) {
$arr = mysql_fetch_assoc($res);
$pollid = $arr["id"];
$userid = $CURUSER["id"];
$question = $arr["question"];
$o = array($arr["option0"], $arr["option1"], $arr["option2"], $arr["option3"], $arr["option4"],
$arr["option5"], $arr["option6"], $arr["option7"], $arr["option8"], $arr["option9"],
$arr["option10"], $arr["option11"], $arr["option12"], $arr["option13"], $arr["option14"],
$arr["option15"], $arr["option16"], $arr["option17"], $arr["option18"], $arr["option19"]);
// Check if user has already voted
$res = sql_query("SELECT * FROM pollanswers WHERE pollid=$pollid AND userid=$userid") or sqlerr(__FILE__, __LINE__);
$arr2 = mysql_fetch_assoc($res);
}
$blocktitle = $tracker_lang['poll'].(get_user_class() >= UC_MODERATOR ? " - [".$tracker_lang['create']."]".($pollok ? " - [Labot] - [Dzēst]" : "")."" : "");
if($pollok) {
$content .= ("$question \n");
$voted = $arr2;
if ($voted) {
// display results
if ($arr["selection"])
$uservote = $arr["selection"];
else
$uservote = -1;
// we reserve 255 for blank vote.
$res = sql_query("SELECT selection FROM pollanswers WHERE pollid=$pollid AND selection < 20") or sqlerr(__FILE__, __LINE__);
$tvotes = mysql_num_rows($res);
$vs = array(); // array of
$os = array();
// Count votes
while ($arr2 = mysql_fetch_row($res))
$vs[$arr2[0]] += 1;
reset($o);
for ($i = 0; $i < count($o); ++$i)
if ($o[$i])
$os[$i] = array($vs[$i], $o[$i]);
function srt($a,$b) {
if ($a[0] > $b[0]) return -1;
if ($a[0] < $b[0]) return 1;
return 0;
}
// now os is an array like this: array(array(123, "Option 1"), array(45, "Option 2"))
if ($arr["sort"] == "yes")
usort($os, srt);
$content .= ("\n");
$i = 0;
while ($a = $os[$i]) {
if ($i == $uservote)
$a[1] .= " *";
if ($tvotes == 0)
$p = 0;
else
$p = round($a[0] / $tvotes * 100);
if ($i % 2)
$c = "";
else
$c = " bgcolor=\"#eeeeee\"";
$content .= ("" . $a[1] . " | " .
"
"\"> $p% | \n");
++$i;
}
$content .= (" \n");
$tvotes = number_format($tvotes);
$content .= ("Votes: $tvotes \n");
} else {
$content .= ("");
}
if ($voted)
$content .= ("\n");
} else {
$content .= "";
$content .= "".$tracker_lang['no_polls']."\n";
$content .= " | ";
}
?>
|