Foros del Web » Programando para Internet » PHP »

como mostrar resultados de la encuesta

Estas en el tema de como mostrar resultados de la encuesta en el foro de PHP en Foros del Web. Hola acabo de ponerle una cookie a la encuesta de mi pagina, la cookie funciona bien deja votar una vez , pero el problema es ...
  #1 (permalink)  
Antiguo 30/09/2007, 20:21
Avatar de hernansam  
Fecha de Ingreso: septiembre-2007
Ubicación: Funes , Argentina
Mensajes: 204
Antigüedad: 16 años, 7 meses
Puntos: 0
como mostrar resultados de la encuesta

Hola acabo de ponerle una cookie a la encuesta de mi pagina, la cookie funciona bien deja votar una vez , pero el problema es que quiero que muestre los resultados , que solo los muestra cuando votan.

El codigo aca

Código PHP:

<? 
    
if(isset($_COOKIE['encuesta'])){
    
    echo 
"<script> window.alert('Ya votaste'); window.location.href = '/portada.php'; </script>";
    
    }else{
        
        include(
"encuesta/config1.php");
        
        
$file2=file($file); 
        
$lineas=count($file2);
        
$n1=$file2[0]; 
        
$n2=$file2[1]; 
        
$n3=$file2[2]; 
        
$n4=$file2[3]; 
        
        
        if(
$En=="E1"
        {
$nn1=intval($n1)+1;}else{$nn1=intval($n1);} 
        if(
$En=="E2"
        {
$nn2=intval($n2)+1;}else{$nn2=intval($n2);} 
        if(
$En=="E3"
        {
$nn3=intval($n3)+1;}else{$nn3=intval($n3);}
        if(
$En=="E4"
        {
$nn4=intval($n4)+1;}else{$nn4=intval($n4);} 
        
            
$fp=fopen($file,"w+"); 
                
fwrite($fp,"$nn1\n$nn2\n$nn3\n$nn4"); 
            
fclose($fp); 
        
        
$ntotal=$nn1+$nn2+$nn3+$nn4
    
?>

<div align="center">
  <table border=0 cellpadding=0 cellspacing=0 width=273>
    <tr>
      <td colspan=3><strong><font face=Arial>Resultados Encuesta</font></strong></td>
    </tr>
    <tr>
      <td width=92 height="77"><font face=Arial><? echo $c;?><strong>Newell 's </strong></font></td>
      <td width=117><table border=0 cellpadding=0 cellspacing=1 width=100
    bgcolor="#000080">
        <tr>
          <td><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=64><p align=center><font face=Arial size=2><? echo $nn1;?></font></td>
    </tr>
    <tr>
      <td width=92 height="83"><font face=Arial><? echo $c;?><strong>Central</strong></font></td>
      <td width=117><table border=0 cellpadding=0 cellspacing=1 width=100%
    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=64><p align=center><font face=Arial size=2><? echo $nn2;?></font></td>
    </tr>
    <tr>
      <td width=92 height="98"><font face=Arial><? echo $c;?><strong>No me Interesa </strong></font></td>
      <td width=117><table border=0 cellpadding=0 cellspacing=1 width=100%
    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=64><p align=center><font face=Arial size=2><? echo $nn3;?></font></td>
    </tr><tr>
      <td colspan=3><font face=Arial>Total encuesta: </font><font
    color=#004080 face=Arial size=2><strong><? echo $ntotal;?></strong></font></td>
    </tr>
  </table>
  <br>
  

  <a href="index.php">Volver</a>
  
</div>
<?php
        
}
?>
  #2 (permalink)  
Antiguo 01/10/2007, 06:01
 
Fecha de Ingreso: octubre-2007
Ubicación: agua dulce, veracruz
Mensajes: 22
Antigüedad: 16 años, 6 meses
Puntos: 1
Re: como mostrar resultados de la encuesta

asi, fijate en lso comentariso, apara que veas lo que cambie


Código PHP:
<?  
    
if(isset($_COOKIE['encuesta'])){ 
     
    echo 
"<script> window.alert('Ya votaste');  </script>";  //quite la redireccion para que se pueda ver los resultados

     
    
}else{ 
         
        include(
"encuesta/config1.php"); 
         
        
$file2=file($file);  
        
$lineas=count($file2); 
        
$n1=$file2[0];  
        
$n2=$file2[1];  
        
$n3=$file2[2];  
        
$n4=$file2[3];  
         
         
        if(
$En=="E1")  
        {
$nn1=intval($n1)+1;}else{$nn1=intval($n1);}  
        if(
$En=="E2")  
        {
$nn2=intval($n2)+1;}else{$nn2=intval($n2);}  
        if(
$En=="E3")  
        {
$nn3=intval($n3)+1;}else{$nn3=intval($n3);} 
        if(
$En=="E4")  
        {
$nn4=intval($n4)+1;}else{$nn4=intval($n4);}  
         
            
$fp=fopen($file,"w+");  
                
fwrite($fp,"$nn1\n$nn2\n$nn3\n$nn4");  
            
fclose($fp);  
         
        
$ntotal=$nn1+$nn2+$nn3+$nn4;  
     

        } 
//el final del else lo puse aqui, para que cualquier apueda ver los resultados
?>

<div align="center"> 
  <table border=0 cellpadding=0 cellspacing=0 width=273> 
    <tr> 
      <td colspan=3><strong><font face=Arial>Resultados Encuesta</font></strong></td> 
    </tr> 
    <tr> 
      <td width=92 height="77"><font face=Arial><? echo $c;?><strong>Newell 's </strong></font></td> 
      <td width=117><table border=0 cellpadding=0 cellspacing=1 width=100 
    bgcolor="#000080"> 
        <tr> 
          <td><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=64><p align=center><font face=Arial size=2><? echo $nn1;?></font></td> 
    </tr> 
    <tr> 
      <td width=92 height="83"><font face=Arial><? echo $c;?><strong>Central</strong></font></td> 
      <td width=117><table border=0 cellpadding=0 cellspacing=1 width=100% 
    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=64><p align=center><font face=Arial size=2><? echo $nn2;?></font></td> 
    </tr> 
    <tr> 
      <td width=92 height="98"><font face=Arial><? echo $c;?><strong>No me Interesa </strong></font></td> 
      <td width=117><table border=0 cellpadding=0 cellspacing=1 width=100% 
    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=64><p align=center><font face=Arial size=2><? echo $nn3;?></font></td> 
    </tr><tr> 
      <td colspan=3><font face=Arial>Total encuesta: </font><font 
    color=#004080 face=Arial size=2><strong><? echo $ntotal;?></strong></font></td> 
    </tr> 
  </table> 
  <br> 
   

  <a href="index.php">Volver</a> 
   
</div>

-Kerberos^^
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:31.