| Current Path : /var/www/html/mmishra/indem/poll/ |
| Current File : /var/www/html/mmishra/indem/poll/poll.inc |
<span id='title'>Opinion Poll</span><br>
<?php
if (!isset($_SESSION["uid"])) {
login($pg);
} else {
$tbl = "poll";
//define subject
$subject = 'T-Shirt';
dbConnect();
$id = $_REQUEST["id"];
if ($id) {
if (mysql_num_rows(mysql_query("select * from $tbl where id=$id"))) {
mysql_query("update $tbl set score=score+1 where id=$id");
} else {
//mysql_query("insert into $tbl(subject,option) values('$subject','$option')");
}
} else if ($action == "del") {
mysql_query("delete from $tbl where id=$id");
}
$rs = mysql_query("select sum(score) as tot from $tbl group by subject having subject='$subject'");
if ($rs) {
$o = mysql_fetch_object($rs);
$tot = $o->tot;
}
echo "Total polls: $tot
<table width='90%' border='1'>
<tr><th>No.</th><th>Option (click to enlarge image)</th><th>Score</th></tr>";
$rs = mysql_query("select * from $tbl where subject='$subject'");
while ($o = mysql_fetch_object($rs)) {
$i++;
$per = ($o->score / $tot) * 100;
echo "<tr valign='center'><td>$i</td>
<td align='center'><a href='$o->image'>";
if ($o->image) echo "<img src='$o->image' width='100' height='100'>";
echo "</a>$o->description</td><td align='center'>$o->score (". number_format($per,2) .")<br>
[ <a href='?pg=$pg&subject=$subject&id=$o->id'>Cast Your Vote</a> ]</td></tr>";
}
echo "</table>";
}
?>