Ver Mensaje Individual
  #7 (permalink)  
Antiguo 13/09/2008, 10:21
Avatar de the_web_saint
the_web_saint
 
Fecha de Ingreso: mayo-2008
Ubicación: localhost/tierra/america/panama
Mensajes: 1.229
Antigüedad: 16 años
Puntos: 43
Respuesta: Encuesta sin bd (aporte)

Creo que lo he solucionado, hice unos cambios, espero no le moleste al autor!
encuesta.php
Código PHP:
<?php 
// El codigo es simple de entender
// Para crear la encuesta hay que ir al archivo ing_encuesta.php
// Recuerda que hay que tener permiso 0777 masomenos.
$key 0;
include (
"funciones.php");
if (!isset(
$_POST['submit']))// si no an apretado el boton
{
 
// incluimos las funciones
 
$archivo abrirf ("pregunta.txt");// abrimos el archivo de las preguntas
 
$limite substr_count($archivo',' ); // Contamos
 
$tupla split','$archivo$limite );// separamos
 
 
echo "
 <body leftmargin='0' topmargin='0'>
 <form name='form1' method='post' action='encuesta.php'>
 <table width='175' border='0' align='left' cellpadding='0' cellspacing='0'>
   <tr>
   </tr>
 "
;// ponemos la parte de arriba de la encesta
 
 
for($i=$i <= $limite ; ++$i)
 {
 if (
$i == 0)
 {
  echo
"
    <tr>
   <td bgcolor='#000000'><font color='#FFFFFF' size='2' face='Arial, Helvetica, sans-serif'>
   $tupla[$i]
   </font></td>
    </tr>
  "
;
 }
 else
 {
 echo
"
   <tr>
  <td valign='top' bgcolor='#999999'><font face='Arial, Helvetica, sans-serif' color='#FFFFFF' size='1'>$i
  <font face='Arial, Helvetica, sans-serif' color='#FFFFFF' size='2'>
    <input type='radio' name='respuesta' value='$i'>$tupla[$i]</font></td>
   </tr>
   "
;// ponemos las preguntas
 
}
 
 }
//fin for
 
 
echo"
   <tr>
  <td bgcolor='#999999'><div align='center'>
  <input type='hidden' name='pregunta' value='$tupla[0]'>
  <input type='submit' name='submit' value='Votar'>
  </div></td>
   </tr>
 </table>
 </form>
 </body>
 "
;
}
//fin  if
if (isset($_POST['submit']))// si apretaron el boton votar
{
 
$archivo abrirf ("encuesta.txt");// abrimos las respuestas
 
$limite substr_count($archivo',' ); // contamos
 
$respuestas=explode(",",$archivo);// separamos
 
if (isset($_POST['respuesta'])) 
 {
  
$respuestas[$_POST['respuesta']-1]++;
  
$f=fopen("encuesta.txt","w");
  
$todas '';
  
$total 0;
  for (
$i $i <= $limite $i++)
  {
  
$total += $respuestas[$i];
   if ((
$limite $i) == 0)
    
$todas .= "$respuestas[$i]";
   else
    
$todas .= "$respuestas[$i],";
  }
 
  
fwrite($f,$todas,strlen($todas));
  
fclose($f); 
 }   
 else
 {
  
$key 1;
 }
 
 if(
$total==0
 {
  for (
$i $i <= $limite $i++)
   
$porcentaje[$i]=0;
 } 
 else 
 {
  for (
$i $i <= $limite $i++)
   
$porcentaje[$i]=sprintf("%1.1f",(($respuestas[$i]/$total)*100));
 }
 if (
$key == 0)
 {
  echo 
"
  <body leftmargin='0' topmargin='0'>
  <table width='175' border='1' bordercolor='7799FF' align='left' cellpadding='0' cellspacing='0'>
    <tr>
   <td colspan='3' bordercolor='000000' bgcolor='#000000'><div align='left'><font color='#FF4400' size='2' face='Arial, Helvetica, sans-serif'>
   $pregunta </font></div>
   </td>
    </tr>
  "
;
  
$ii 1;
  for (
$i $i <= $limite $i++,$ii++)
  {
  echo
"
   <tr bgcolor='#FFFFFF'>
   <td bordercolor='FFFFFF'><font face='Verdana' size='1'>$ii</font></td>
   <td bordercolor='FFFFFF' align='left'><img src='barra.gif' height='15' width='$porcentaje[$i]'></td>
   <td bordercolor='FFFFFF' align='left'><font face='Verdana' size='1'>$porcentaje[$i]%</font></td> 
   </tr>
  "
;
  }
 
  echo 
" </table>
    </body>"
;
 }
 else
// si no
 
{
  echo 
"
    <body leftmargin='0' topmargin='0'> 
    <table width='175' bgcolor='999999'>
    <tr><td>
    <font face='Verdana' size='1' color='FFFFFF'>Debe marcar una opción para poder acceder a los resultados de la consulta para regresar <a href='javascript:history.back()'><font color='#FFFF00'>click aquí</font></a>
    </td></tr>
    </table>
    </body>"
;
 }
}
?>
ing_encuesta.php
Código PHP:
<html>
<head>
<title>Ingreso de Encuestas</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
 
<body>
<?php
if (!isset($_POST['submit']) && !isset($_POST['submit1']))
{
echo 
"
<form name='form' action='ing_encuesta.php' method='post'>
    <table>
    <tr>
        <td align='center' colspan='2'><font face='Arial' size='2'><strong>Ingreso de la pregunta</strong></font></td>
    </tr>
    <tr>
        <td><font face='Arial' size='2'>Ingrese la pregunta:</font></td>
        <td><input type='text' name='pregunta' value=''></td>
    </tr>
    <tr>
        <td><font face='Arial' size='2'>Ingrese # opciones:</font></td>
        <td><input type='text' name='n' value=''></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input type='submit' name='submit' value='Aceptar'></td>
    </tr>
</form>
"
;
}
 
if (isset(
$_POST['submit']))
{
    echo 
"    <table>
            <tr><td><font face='Arial' size='2'>La pregunta es: "
.$_POST['pregunta']."</font>
            </td></tr>
            <tr><td>
            <form name='form1' action='ing_encuesta.php' method='post'>"
;
    for (
$i $i $_POST['n'] ; $i++)
    {
        echo
"
        <font face='Arial' size='2'>Opcion "
.($i+1).":</font> <input type='text' name='op$i' value=''><br>
        "
;
    }
    echo
"    <input type='submit' name='submit1' value='Aceptar'>
            <input type='hidden' name='limite' value='"
.$_POST['n']."'>
            <input type='hidden' name='pregunta' value='"
.$_POST['pregunta']."'>
            </form>
            </td></tr>
            </table>
            "
;
}
 
if (isset(
$_POST['submit1']))
{
$key 0;
$todas '';
$contador '';
for (
$i $i $_POST['limite'] ; $i++)
{
    
$aux=$_POST['op'.$i];
    if( 
$aux == '')
    {
        echo 
"<font face='Arial' size='2'>Falta información, para ingresar los datos <a href='javascript:history.back()'>click aqui</a></font>";
        
$key 1;
        break;
    }
    else
    {
        
$todas .= ",".$aux;
        if ((
$_POST['limite'] - $i) == 1)
            
$contador .= "0";
        else
            
$contador .= "0,";
    }
}
 
if (
$key == 0)
{
$pregunta=$_POST['pregunta']; 
$todo $pregunta.$todas;        //    echo $todo;        echo $contador;
include ("funciones.php");
        
//Archivo de la pregunta
        
$archivo trim("$todo");
        
guardarf ("pregunta.txt",$archivo);
        
//Archivo de las respuestas
        
$archivo trim("$contador");
        
guardarf ("encuesta.txt",$archivo);
 
echo 
"<br><font face='Arial' size='2'>Creada con exito</font>";
echo 
'<a href="ing_encuesta.php">&lt;&lt; Regresar a Crear Encuentas</a>';
}
 
}
 
?>
</body>
</html>
las funciones queda igual!
al autor!
Saludos
__________________
..::The Saint::..
El pesimista se queja del viento; el optimista espera que cambie; el realista ajusta las velas.