Ciao a tutti,
ho scaricato questo sondaggio che mi funziona perfettamente.
Il problema nasce, però, quando lo includo nella pagina index del mio sito.
Cerco di spiegarmi.
Tramite include inserisco il sondaggio nella mia pagina index,
quando visualizzo la popup mi visualizza tutta la pagina index
mentre io vorrei che mi visualizzasse solo i risultati del sondaggio.
Ringrazio anticipatamente.
Codice PHP:
<?
require_once("finestra.jsp");
require_once("settings.inc");
include ("../include/config.php");
$checkforcurrent = mysql_query("select id,dateactive from polls where active='yes' order by question limit 1");
$current_poll = mysql_fetch_row($checkforcurrent);
$curpollid = $current_poll[0];
$dateactive = $current_poll[1];
$today=date("Y-m-d 00:00");
$date1=strtotime( "$dateactive 00:00" );
$date2=strtotime("$today");
$datediffer = (($date2-$date1)/86400);
if ($datediffer>=$interval){
$lookfornext = mysql_query("select id from polls where active='no' order by id limit 1");
$getnextid = mysql_fetch_row($lookfornext);
$nextpollid = $getnextid[0];
if ($nextpollid){
$date = date("Y-m-d");
mysql_query("update polls set active='end' where id=$curpollid");
mysql_query("update polls set active='yes', dateactive='$date' where id=$nextpollid");
mysql_query("delete from poll_ip");
}
}
function writeresults (){
$getquestion = mysql_query("select id,question,votes from polls where active='yes' order by question limit 1")
or die (mysql_error());
$question = mysql_fetch_row($getquestion);
echo "<font face=\"Verdana\" size=\"2\">[b]".$question[1]."[/b]
";
$totalvotes = $question[2];
$getresults = mysql_query("select votes, alternative from poll_alternatives where poll_id='$question[0]'")
or die (mysql_error());
$imageid=1;
while ($result = mysql_fetch_array($getresults)){
if ($totalvotes!=0){
$percentage = (round(($result["votes"]/$totalvotes)*10000))/100;
}
$imagewidth = round($percentage*2);
print "<table width=100% border=0>";
print "<tr>";
print "<td bgcolor=#99FF00 width=40%>";
print $result["alternative"]."</td>";
print "<td align=left valign=middle bgcolor=#FFCC00 style=font-family: Verdana; font-size: 12px>";
print "<img src=\"$imageid.gif\" width=\"$imagewidth\" height=10>";
print "</td>";
print "<td align=right width=7% valign=middle bgcolor=#33FF00 style=font-family: Verdana; font-size: 12px>";
print $result["votes"]."</td>";
print "<td align=right width=10% valign=middle bgcolor=#0033FF style=font-family: Verdana; font-size: 12px>";
print " $percentage% "."</td>";
$imageid++;
print "</tr>";
print "</table>";
}
echo "
Per questo sondaggio sono stati espressi $totalvotes voti</font>";
}
if(!isset($_POST['submit']) & !isset($_GET['results'])) {
?>
<form method="post" target="miaPop" onsubmit="Popup('miaPop')" >
<font face="Verdana" size="2">
<?
$getquestion = mysql_query("select id,question from polls where active='yes' order by question limit 1")
or die (mysql_error());
$question = mysql_fetch_row($getquestion);
$pollid = $question[0];
$dateactive = $question[1];
$question = $question[1];
echo "[b]$question[/b]
";
$getalternatives = mysql_query("select id, alternative from poll_alternatives where poll_id='$pollid'")
or die (mysql_error());
while ($writeit = mysql_fetch_array($getalternatives)){
print "<table width=128 border=0>";
print "<tr>";
print "<td bgcolor=#99FF00 width=40%>";
echo " ".$writeit["alternative"];
print "<td align=right width=1% valign=middle bgcolor=#33FF00 style=font-family: Verdana; font-size: 12px>";
echo "<input type=\"radio\" name=polloption value=\"".$writeit["id"]."\"";
if (!isset($checkedvar)){ echo "checked"; $checkedvar=1; }
echo ">";
echo "</td>";
print "</tr>";
print "</table>";
}
echo "<input type=\"hidden\" name=\"pollid\" value=\"$pollid\"></font>";
echo "
<center><input type=\"Submit\" value=\"Vota\" name=\"submit\"";
echo " style=\"background-color:red; color:yellow; border:yellow; font-family:Verdana; font-size:12px\">
";
echo "<a href=javascript:finestra(\"".$_SERVER['PHP_SELF']."?results=1\")> Visualizza risultati </a>";
echo "</center></form>";
}
elseif (isset($_POST['submit'])){
$indirizzo = $_SERVER['REMOTE_ADDR'];
$opzione = $_POST['polloption'];
$voto = $_POST['pollid'];
$checkforip = mysql_query("select ip from poll_ip where ip='$indirizzo'");
if (mysql_num_rows($checkforip)==0){
mysql_query ("update poll_alternatives set votes=votes+1 where id='$opzione'")
or die (mysql_error());
mysql_query ("update polls set votes=votes+1 where id='$voto'")
or die (mysql_error());
mysql_query ("insert into poll_ip (ip) values ('$indirizzo')")
or die (mysql_error());
echo "<font face=\"Verdana\" size=\"2\">Il tuo voto è stato calcolato.
</font>";
}
else { echo "<font face=\"Verdana\" size=\"2\">Spiacente per questo sondaggio si può votare una sola volta.
</font>";
}
writeresults();
}
elseif ($_GET['results']){
writeresults();
}