Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/12/2007, 04:30
Avatar de hernansam
hernansam
 
Fecha de Ingreso: septiembre-2007
Ubicación: Funes , Argentina
Mensajes: 204
Antigüedad: 16 años, 7 meses
Puntos: 0
Mostrar la cantidad de gente que voto en encuesta

Hola amigos , quiero modificar una encuesta, lo que quiero hacer es que me muestre la cantidad de personas que votaron en la encuesta.

Código HTML:
<form name="encuesta" action="hj" method="post"">
 ¿Pregunta?<br>
 <input type=radio name="respuesta" Value="1"> OpcionA <br>
 <input type=radio name="respuesta" Value="2"> OpcionB <br>
 <input type=radio name="respuesta" Value="3"> OpcionC <br>
 <input type="submit" value="Votar">
</form> 
Código PHP:
<?php

error_reporting
(2048);
$f=fopen("encuesta.txt","r");
if(
$f){echo "";}
else{echo 
"No puedo abrir f";}
$todas=fread($f,filesize("encuesta.txt"));
$respuestas=explode(",",$todas);
fclose($f);

if (
$respuesta) {

$respuestas[$respuesta-1]++;
$f=fopen("encuesta.txt","w");

$todas=$respuestas[0].",".$respuestas[1].",".$respuestas[2];
fwrite($f,$todas,strlen($todas));
fclose($f);
}

$total=$respuestas[0]+$respuestas[1]+$respuestas[2];
if(
$total==0) {
$porcentaje[0]=0;
$porcentaje[1]=0;
$porcentaje[2]=0;
} else {
$porcentaje[0]=sprintf("%1.2f",(($respuestas[0]/$total)*100));
$porcentaje[1]=sprintf("%1.2f",(($respuestas[1]/$total)*100));
$porcentaje[2]=sprintf("%1.2f",(($respuestas[2]/$total)*100));
}



?>



</div>
<table border="0" align="center">
<tr>
<td colspan="3" align="center">
¿Quien gana las elecciones en Rosario Central?
</td>
</tr>
<tr>
<td align="left">
<?php echo "$porcentaje[0]%"?>
</td>
<td align="left">
<img src="red.png" height="15" width="<?php echo "$porcentaje[0]"?>">
</td>
<td>
A
</td>
</tr>
<tr>
<td align="left">
<?php echo "$porcentaje[1]%"?>
</td>
<td align="left">
<img src="blue.png" height="15" width="<?php echo "$porcentaje[1]"?>">
</td>
<td>
B
</td>
</tr>
<tr>
<td align="left">
<?php echo "$porcentaje[2]%"?>
</td>
<td align="left">
<img src="yellow.png" height="15" width="<?php echo "$porcentaje[2]"?>">
</td>
<td>
C
</td>
</tr>
</table>
<div align="center"><br>
</div>
<div align="center"><strong></strong></div>
<div align="center"><strong>Hernansam.com</strong>
     
?>