El caso es que yo tengo 3 archivos php. En el primero tengo la encuesta
Código PHP:
<table width="364" border="0" align="center" bordercolor="#000000" bgcolor="#CCCCCC">
<tr>
<td colspan="2"><div align="center"><span class="Estilo30 Estilo35">¿Irás a la playa? </span></div></td>
</tr>
<tr>
<td width="233"><span class="Estilo30">
<?
include("config.php"); //incluimos el fichero config.php donde tenemos la configuración del script
if(!file_exists($file)) //si el txt no existe...
{
$fp=fopen($file,"w"); //creamos un txt por si no tá creado
fputs($fp,"0\n0\n0\n0"); //le ponemos las respuestas desde 0
fclose($fp); //cerramos el txt
}
?>
</span></td>
<td width="121"> </td>
</tr>
<tr>
<td height="63" colspan="2"><form method="post" action="enc_ver.php">
<blockquote>
<blockquote>
<p>
<input name="En" type="radio" value="E1" />
<? echo $c1;?><br />
<input type="radio" name="En" value="E2" />
<? echo $c2;?><br />
<input type="radio" name="En" value="E3" />
<? echo $c3;?><br />
</p>
<blockquote>
<blockquote>
<p align="left">
<input type="submit" value="Votar" name="Bot2" />
</p>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</form></td>
</tr>
<tr>
<td height="17" colspan="2" align="center" valign="top" bgcolor="#003366"><div align="right" class="Estilo37"><a href="enc_ver.php">Ver resultados</a> </div></td>
</tr>
</table>
En otro tengo las opciones:
Código PHP:
<?
// CONFIGURACION DE LA ENCUESTA
$file="base.txt"; //nombre del txt en el que guardaremos los resultados
//Escribe tus respuestas para la encuesta
$c1="Si"; //Encuesta nº 1
$c2="No lo sé"; //Encuesta nº 2
$c3="No"; //Encuesta nº 3
?>
y en el otro tengo los resultados:
Código PHP:
<?
include("config.php"); //incluimos el fichero config.php donde tenemos la configuración del script
$file2=file($file); //creamos el array con las lineas del archivo
$lineas=count($file2);//contamos los elementos del array, es decir el total de lineas
$n1=$file2[0]; //asignamos a la variable el nº de votos(la línea 1 del txt)
$n2=$file2[1]; //asignamos a la variable el nº de votos(la línea 2 del txt)
$n3=$file2[2]; //asignamos a la variable el nº de votos(la línea 3 del txt)
$n4=$file2[3]; //asignamos a la variable el nº de votos(la línea 4 del txt)
if($En=="E1") //si la respuesta es la opción 1...
{$nn1=intval($n1)+1;}else{$nn1=intval($n1);} //entonces sumamos uno a $nn1, si no, se keda igual
if($En=="E2") //si la respuesta es la opción ...
{$nn2=intval($n2)+1;}else{$nn2=intval($n2);} //entonces sumamos uno a $nn2, si no, se keda igual
if($En=="E3") //si la respuesta es la opción 3...
{$nn3=intval($n3)+1;}else{$nn3=intval($n3);} //entonces sumamos uno a $nn3, si no, se keda igual
if($En=="E4") //si la respuesta es la opción 4...
{$nn4=intval($n4)+1;}else{$nn4=intval($n4);} //entonces sumamos uno a $nn4, si no, se keda igual
$fp=fopen($file,"w+"); //abrimos de nuevo el txt borrándolo todo
fwrite($fp,"$nn1\n$nn2\n$nn3\n$nn4"); //escribimos en el txt los votos.. en su respectiva línea. NOTA: \n <- cambia de línea ;)
fclose($fp); //cerramos el txt
$ntotal=$nn1+$nn2+$nn3+$nn4; //contamos el nº total de votos
?>
</p>
<table width=479 height="254" border=0 align="center" cellpadding=0 cellspacing=0>
<tr>
<td colspan=3 width=186><div align="center" class="Estilo27 Estilo34">Resultados de la encuesta</div></td>
</tr>
<tr>
<td width=186><font face=Arial><? echo $c1;?></font></td>
<td width=186><table border=0 cellpadding=0 cellspacing=1 width=67
bgcolor="#000080">
<tr>
<td width=100%><table border=0 cellpadding=0 cellspacing=0 width=<? echo $nn1*100/$ntotal;?> bgcolor=#FFFFFF
height=5>
<tr>
<td></td>
</tr>
</table></td>
</tr>
</table></td>
<td width=186><p align=center><font face=Arial size=2><? echo $nn1;?></font></p></td>
</tr>
<tr>
<td width=186><font face=Arial><? echo $c2;?></font></td>
<td width=186><table width=41% height="9" border=0 cellpadding=0 cellspacing=1
bgcolor=#000080>
<tr>
<td width=100%><table border=0 cellpadding=0 cellspacing=0 width=<? echo $nn2*100/$ntotal;?>
bgcolor=#FFFFFF height=5>
<tr>
<td></td>
</tr>
</table></td>
</tr>
</table></td>
<td width=186><p align=center><font face=Arial size=2><? echo $nn2;?></font></p></td>
</tr>
<tr>
<td width=186><font face=Arial><? echo $c3;?></font></td>
<td width=186><table border=0 cellpadding=0 cellspacing=1 width=40%
bgcolor=#000080>
<tr>
<td width=100%><table border=0 cellpadding=0 cellspacing=0 width=<? echo $nn3*100/$ntotal;?>
bgcolor=#FFFFFF height=5>
<tr>
<td></td>
</tr>
</table></td>
</tr>
</table></td>
<td width=186><p align=center><font face=Arial size=2><? echo $nn3;?></font></p></td>
</tr>
<tr>
<td width=186 colspan=3><div align="center"><span class="Estilo14 Estilo27 Estilo35">Votaciones totales </span><font face=Arial>: </font><font
color=#FFFFFF face=Arial size=2><strong><? echo $ntotal;?></strong></font></div></td>
</tr>
</table>
No hay ninguna funcion que se le pueda añadir para que no se pueda votar mas de una vez??
Gracias denuevo