Ver Mensaje Individual
  #27 (permalink)  
Antiguo 08/07/2015, 13:50
Avatar de chronos682
chronos682
 
Fecha de Ingreso: febrero-2004
Ubicación: Tunja - Boyacá - Colombia
Mensajes: 627
Antigüedad: 21 años, 1 mes
Puntos: 69
Respuesta: Repetir una función 3 veces

La idea es que tu aprendas a hacer las cosas por tu cuenta porque si se te dan las cosas hechas va a ser más difícil que aprendas, de todas formas aquí está el código, trata de analizarlo y aprender cómo se hace:

Código PHP:
Ver original
  1. <!DOCTYPE html>
  2. <html lang="es">
  3. <head>
  4.     <title>Prueba</title>
  5.     <?php
  6.                 require_once("includes/connection.php");
  7.         if (isset($_GET['tematicasId']) && !isset($_POST['submit']))
  8.         {
  9.             $aux=$_GET['tematicasId'];
  10.             if ($aux=='1')
  11.             {
  12.                 $sTematica="Matematicas";
  13.                 $show='0';
  14.             }
  15.             else
  16.             {
  17.                 echo "Se ha especificado una tematica no valida";
  18.                 exit;
  19.             }
  20.         }
  21.         else
  22.         {
  23.             if (isset($_POST['submit']))
  24.             {
  25.                 $sTematica="Matematicas"; //Este se debe obtener por un switch o if comparando tematicasid
  26.                 $aux='1'; //Este se debe pasar por GET
  27.                 $respuestas=$_POST['respuesta'];
  28.                 $show='1';
  29.             }
  30.             else
  31.             {
  32.                 echo "No se ha especificado una tematica de la evaluacion";
  33.                 exit;
  34.             }
  35.         }
  36.     ?>
  37. </head>
  38. <body>
  39.     <?php
  40.         $sql = "SELECT * FROM Evaluaciones WHERE tematicasId='".$aux."' AND ID_eval='1'";
  41.         $result = mysql_query($sql) or die(mysql_error());
  42.         $iNumReg = mysql_num_rows($result);
  43.     ?> 
  44.     <?php echo "<h1>Evaluacion de ".$sTematica."</h1><br>";?>
  45.     <table width="615" border="1">
  46.         <form action='' method='post'>
  47.             <?php
  48.                 if ($show=='0')
  49.                 {
  50.                     if ($iNumReg>0)
  51.                     {
  52.                         $i = 0;  
  53.                         while ($rowEmp = mysql_fetch_assoc($result))
  54.                         {
  55.                             $dbpregunta = $rowEmp['evaluacionPregunta'];
  56.                             $dbR1=$rowEmp['evaluacionR1'];
  57.                             $dbR2=$rowEmp['evaluacionR2'];
  58.                             $dbR3=$rowEmp['evaluacionR3'];
  59.                             echo "<tr>";
  60.                                 echo "<td colspan='3'>Pregunta: ".$dbpregunta."</td>";
  61.                             echo "</tr>";
  62.                             echo "<tr>";
  63.                                 echo "<td width='38'>Opcion</td>";
  64.                                 echo "<td width='486'>Respuesta</td>";
  65.                                 echo "<td width='69'>Correcta</td>";
  66.                             echo "</tr>";
  67.                             echo "<tr>";
  68.                                 echo "<td>a</td>";
  69.                                 echo "<td>".$dbR1."</td>";
  70.                                 echo "<td><input name='respuesta[".$i."]' type='radio' value='1'></td>";
  71.                             echo "</tr>";
  72.                             echo "<tr>";
  73.                                 echo "<td>b</td>";
  74.                                 echo "<td>".$dbR2."</td>";
  75.                                 echo "<td><input name='respuesta[".$i."]' type='radio' value='2'></td>";
  76.                             echo "</tr>";
  77.                             echo "<tr>";
  78.                                 echo "<td>c</td>";
  79.                                 echo "<td>".$dbR3."</td>";
  80.                                 echo "<td><input name='respuesta[".$i."]' type='radio' value='3'></td>";
  81.                             echo "</tr>";
  82.                             $i += 1;
  83.                         }
  84.                     }
  85.                 }
  86.                 else
  87.                 {
  88.                     if ($iNumReg>0)
  89.                     {
  90.                         $i = 0;  
  91.                         while ($rowEmp = mysql_fetch_assoc($result))
  92.                         {
  93.                             $dbpregunta = $rowEmp['evaluacionPregunta'];
  94.                             $dbR1=$rowEmp['evaluacionR1'];
  95.                             $dbR2=$rowEmp['evaluacionR2'];
  96.                             $dbR3=$rowEmp['evaluacionR3'];
  97.                             $dbcorrecta=$rowEmp['Correcta'];
  98.                             echo "<tr>";
  99.                                 echo "<td colspan='3'>Pregunta: ".$dbpregunta."</td>";
  100.                             echo "</tr>";
  101.                             echo "<tr>";
  102.                                 echo "<td width='38'>Opcion</td>";
  103.                                 echo "<td width='486'>Respuesta</td>";
  104.                                 echo "<td width='69'>Resultado</td>";
  105.                             echo "</tr>";
  106.                             echo "<tr>";
  107.                                 echo "<td>a</td>";
  108.                                 if ($respuestas[$i]=='1')
  109.                                 {
  110.                                     echo "<td style='background-color: beige;'>".$dbR1." (Seleccionada)</td>";
  111.                                 }
  112.                                 else
  113.                                 {
  114.                                     echo "<td>".$dbR1."</td>";
  115.                                 }
  116.                                 if ($respuestas[$i]==$dbcorrecta)
  117.                                 {
  118.                                     echo "<td style='background-color: aquamarine;' rowspan='3'>Bien</td>";
  119.                                 }
  120.                                 else
  121.                                 {
  122.                                     echo "<td style='background-color: salmon;'rowspan='3'>Mal</td>";
  123.                                 }
  124.                             echo "</tr>";
  125.                             echo "<tr>";
  126.                                 echo "<td>b</td>";
  127.                                 if ($respuestas[$i]=='2')
  128.                                 {
  129.                                     echo "<td style='background-color: beige;'>".$dbR2." (Seleccionada)</td>";
  130.                                 }
  131.                                 else
  132.                                 {
  133.                                     echo "<td>".$dbR2."</td>";
  134.                                 }
  135.                             echo "</tr>";
  136.                             echo "<tr>";
  137.                                 echo "<td>c</td>";
  138.                                 if ($respuestas[$i]=='3')
  139.                                 {
  140.                                     echo "<td style='background-color: beige;'>".$dbR3." (Seleccionada)</td>";
  141.                                 }
  142.                                 else
  143.                                 {
  144.                                     echo "<td>".$dbR3."</td>";
  145.                                 }
  146.                             echo "</tr>";
  147.                             $i += 1;
  148.                         }
  149.                     }
  150.                 }
  151.                 echo "<tr>";
  152.                     if ($show=='0')
  153.                     {
  154.                         echo "<td><br><br></td><td style='text-align: center;'><input name='submit' type='submit' value='Enviar evaluacion'></td>";
  155.                     }
  156.                     else
  157.                     {
  158.                         echo "<td><br><br></td><td style='text-align: center;'><a href='prueba.php?tematicasId=1'>Volver</a></td>";
  159.                     }
  160.                 echo "</tr>";
  161.             ?>
  162.         </form>
  163.     </table>
  164. </body>
  165. </html>

Espero te sea de ayuda, de todas formas tienes que aprender a hacerlo por tu cuenta.
__________________
Si te gustó la respuesta dale +1

HERNÁN G. SIABATO M.
[email protected]

Última edición por chronos682; 08/07/2015 a las 14:07