|
|
·
Skindario
Buscar en el Foro Buscar Tags
Portal
Foro
Usuario
Foro
Normas
RSS
Etiquetas
Avatares
Rangos
Eventos
Staff
Entrevistas
Noticias
Caretos
F.A.Q
Subforos Privados
Estadisticas
Estadisticas
Usuarios
OnLine
Actividad
Funciones
Favoritos
P. Inicio
Imprimir
Buscar
Afiliados
¿Tu Web Aquí?
Comunidad ESDLA
Foros DWP
Websmasters Foro
Mundo Deluxe
Photosherox
Descargas-V
Enlázanos

Encuesta sin mysql
Haz clic para publicar un nuevo tema Haz clic para añadir una nueva respuesta · Portal · Foros · PHP
Buscar · Tags · Imágenes · Usuarios · Fisgona · F.A.Q.
Autor Mensaje 
EffectedCard
Administrador
Administrador

Haz clic para ver el perfil del usuario

Usuario PRO Usuario PRO
Mensajes: 9.094
Desde: 16/Oct/2004
Encuesta sin mysql

Este script consta de 3 archivos .php y no necesita la base datos:
index.php (Indice)

Codigo PHP:

<?
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,"0n0n0n0"); //le ponemos las respuestas desde 0
    
fclose($fp); //cerramos el txt
    
}
?>
<form method=POST action="enc_ver.php">
    <input type="radio" name="En" value="E1" checked><? echo $c1;?><br>
    <input type="radio" name="En" value="E2"><? echo $c2;?><br>
    <input type="radio" name="En" value="E3"><? echo $c3;?><br>
    <input type="radio" name="En" value="E4"><? echo $c4;?><br>
    <input type="submit" value="OK" name="Bot">
</form>
<p>






config.php(para configurar la encuesta)

Codigo PHP:

<?
// CONFIGURACION DE LA ENCUESTA
$file="base.txt"; //nombre del txt en el que guardaremos los resultados

//Escribe tus respuestas para la encuesta
$c1="Nº 1"; //Encuesta nº 1
$c2="Nº 2"; //Encuesta nº 2
$c3="Nº 3"; //Encuesta nº 3
$c4="Nº 4"; //Encuesta nº 4
?>







enc_ver.php (Resultados)

Codigo 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,"$nn1n$nn2n$nn3n$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
?>
<table border=0 cellpadding=0 cellspacing=0 width=188>
  <tr>
    <td colspan=3 width=186><strong><font face=Arial>Resultados Encuesta</font></strong></td>
  </tr>
  <tr>
    <td width=46><font face=Arial><? echo $c1;?></font></td>
    <td width=101><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=37><p align=center><font face=Arial size=2><? echo $nn1;?></font></td>
  </tr>
  <tr>
    <td width=46><font face=Arial><? echo $c2;?></font></td>
    <td width=101><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=37><p align=center><font face=Arial size=2><? echo $nn2;?></font></td>
  </tr>
  <tr>
    <td width=46><font face=Arial><? echo $c3;?></font></td>
    <td width=101><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=37><p align=center><font face=Arial size=2><? echo $nn3;?></font></td>
  </tr>
  <tr>
    <td width=46><font face=Arial><? echo $c4;?></font></td>
    <td width=101><table border=0 cellpadding=0 cellspacing=1 width=100%
    bgcolor=#000080>
      <tr>
        <td width=100%><table border=0 cellpadding=0 cellspacing=0 width=<? echo $nn4*100/$ntotal;?>
        bgcolor=#FFFFFF height=5>
          <tr>
            <td></td>
          </tr>
        </table>
        </td>
      </tr>
    </table>
    </td>
    <td width=37><p align=center><font face=Arial size=2><? echo $nn4;?></font></td>
  </tr>
  <tr>
    <td width=184 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>



27/Jul/2005 16:50 GMT+1 Perfil ·  Privado · Desconectado ·  Web
Haz clic para ir al tema anterior Haz clic para ir al tema siguiente
Haz clic para añadir una nueva respuesta · Portal · Foros · PHP
Temas similares Autor#VisitasÚltimo post
Banear IP sin MYSQL27/Jul/2005, 16:36
EffectedCard
 0 293No hay respuestas
Buscador Interno sin mysql27/Jul/2005, 16:48
EffectedCard
 0 1.399No hay respuestas
Conexión a MySQL15/Jun/2007, 16:33
Nigellus
 0 287No hay respuestas
Sistema de eventos [PHP y MySQL]03/May/2008, 16:20
Darth_Carl
 0 294No hay respuestas
Banear IP de una web con MYSQL27/Jul/2005, 16:36
EffectedCard
 0 436No hay respuestas
Opciones:
Versión imprimible del tema
Subscríbete a este tema
Date de baja de este tema
Menear este tema en meneame.net
Ir al subforo:  

TU NO PUEDES Escribir nuevos temas en este foro
TU NO PUEDES Responder a los temas en este foro
TU NO PUEDES Editar tus propios mensajes en este foro
TU NO PUEDES Borrar tus propios mensajes en este foro
Todas las fechas y horas son GMT+1. Ahora son las 00:48

Afiliados Plus
Skindario - Soporte Webmasters, Diseño Grafico, Miarroba, Rol + RPG y Mucho Mas TuarrobaGames - Emuladores, Roms, Juegos y RPG TuarrobaEbooks - Ebooks en castellano y Audiolibros Websmasters foro MundoDeluxe Photosherox - Diseñando & Aprendiendo
¿Tu Web Aquí?
Admin: EffectedCard - Skindario, foro soporte de Tuarroba desde el 16/10/04