Ver Mensaje Individual
  #30 (permalink)  
Antiguo 09/07/2015, 14:43
diegodelpiero
 
Fecha de Ingreso: mayo-2015
Mensajes: 53
Antigüedad: 9 años, 8 meses
Puntos: 0
Respuesta: Repetir una función 3 veces

tengo una duda, quiero poner un if al principio de todo el codigo que me enviaste en el cual valide una consulta a la tabla de notas, si el campo estudianteId de la tabla notas es mayor a cero, significa que el estudiante ya presento una evaluacion, si no que proceda a hacer la evaluacion, pero tengo problemas al colocar el else, si cierro el if en la linea 42, obviamente no me muestra las opciones para responder pero igual me envía información a la base de datos.
Código PHP:
Ver original
  1. <?php
  2. if ($row_Recordset3['estudianteId']>0)
  3. {
  4.     echo"Ya presentaste tu evaluacion";
  5. }
  6. else
  7.     { [B]esta llave no se donde cerrarla, si la cierro al final de todo me da error[/B]
  8.  
  9.     if (isset($_GET['tematicasId']) && !isset($_POST['submit']))
  10.     {
  11.         @$aux=$_GET['tematicasId'];
  12.         @$var=$row_Recordset1['tematicasId'];
  13.         if ($aux==$var)
  14.         {
  15.             $sTematica=$row_Recordset1['tematicasId'];
  16.             $show='0';
  17.             @$respuestas=$_POST['respuesta'];
  18.         }
  19.         else
  20.         {
  21.             echo "Se ha especificado una tematica no valida";
  22.             exit;
  23.         }
  24.     }
  25.     else
  26.     {
  27.        
  28.         if (isset($_POST['submit']))
  29.         {
  30.             @$aux=$_GET['tematicasId'];
  31.             @$sTematica=$row_Recordset1['tematicasId'];
  32.             @$respuestas=$_POST['respuesta'];
  33.             @$show='1';
  34.            
  35.         }
  36.         else
  37.         {
  38.             echo "No se ha especificado una tematica de la evaluacion";
  39.             exit;
  40.         }
  41.     }
  42.  
  43. ?>
  44. <?php
  45. @$sql = "SELECT * FROM evaluaciones WHERE tematicasId='".$aux."'";
  46. @$result = mysql_query($sql) or die(mysql_error());
  47. @$iNumReg = mysql_num_rows($result);
  48.  
  49. ?>
  50. <table width="615" border="1">
  51.     <form action='' method='post'>
  52.         <?php
  53.         if (@$show=='0')
  54.         {
  55.             if ($iNumReg>0)
  56.             {
  57.                 $i = 0;  
  58.                 while ($rowEmp = mysql_fetch_assoc($result))
  59.                 {
  60.                     @$dbpregunta = $rowEmp['evaluacionPregunta'];
  61.                     @$dbR1=$rowEmp['evaluacionR1'];
  62.                     @$dbR2=$rowEmp['evaluacionR2'];
  63.                     @$dbR3=$rowEmp['evaluacionR3'];
  64.                     echo "<tr>";
  65.                         echo "<td colspan='3'>Pregunta: ".$dbpregunta."</td>";
  66.                     echo "</tr>";
  67.                     echo "<tr>";
  68.                         echo "<td width='38'>Opcion</td>";
  69.                         echo "<td width='486'>Respuesta</td>";
  70.                         echo "<td width='69'>Correcta</td>";
  71.                     echo "</tr>";
  72.                     echo "<tr>";
  73.                         echo "<td>a</td>";
  74.                         echo "<td>".$dbR1."</td>";
  75.                         echo "<td><input name='respuesta[".$i."]' type='radio' value='1' required></td>";
  76.                     echo "</tr>";
  77.                     echo "<tr>";
  78.                         echo "<td>b</td>";
  79.                         echo "<td>".$dbR2."</td>";
  80.                         echo "<td><input name='respuesta[".$i."]' type='radio' value='2' required></td>";
  81.                     echo "</tr>";
  82.                             echo "<tr>";
  83.                                 echo "<td>c</td>";
  84.                                 echo "<td>".$dbR3."</td>";
  85.                                 echo "<td><input name='respuesta[".$i."]' type='radio' value='3' required></td>";
  86.                             echo "</tr>";
  87.                             $i += 1;
  88.                 }
  89.             }
  90.         }
  91.                 else
  92.                 {
  93.                
  94.                     if ($iNumReg>0)
  95.                     {
  96.                         $i = 0;  
  97.                         while ($rowEmp = mysql_fetch_assoc($result))
  98.                         {
  99.                             $dbpregunta = $rowEmp['evaluacionPregunta'];
  100.                             $dbR1=$rowEmp['evaluacionR1'];
  101.                             $dbR2=$rowEmp['evaluacionR2'];
  102.                             $dbR3=$rowEmp['evaluacionR3'];
  103.                             $dbcorrecta=$rowEmp['evaluacionRCorrecta'];
  104.                             echo "<tr>";
  105.                                 echo "<td colspan='3'>Pregunta: ".$dbpregunta."</td>";
  106.                             echo "</tr>";
  107.                             echo "<tr>";
  108.                                 echo "<td width='38'>Opcion</td>";
  109.                                 echo "<td width='486'>Respuesta</td>";
  110.                                 echo "<td width='69'>Resultado</td>";
  111.                             echo "</tr>";
  112.                             echo "<tr>";
  113.                                 echo "<td>a</td>";
  114.                                 if (@$respuestas[$i]=='1')
  115.                                 {
  116.                                     echo "<td style='background-color: beige;'>".$dbR1." (Seleccionada)</td>";
  117.                                 }
  118.                                 else
  119.                                 {
  120.                                     echo "<td>".$dbR1."</td>";
  121.                                 }
  122.                                 if (@$respuestas[$i]==$dbcorrecta)
  123.                                 {
  124.                                     echo "<td style='background-color: aquamarine;' rowspan='3'>Bien</td>";
  125.                                     @$acum=$acum+1;
  126.                                 }
  127.                                 else
  128.                                 {
  129.                                     echo "<td style='background-color: salmon;'rowspan='3'>Mal</td>";
  130.                                 }
  131.                             echo "</tr>";
  132.                             echo "<tr>";
  133.                                 echo "<td>b</td>";
  134.                                 if (@$respuestas[$i]=='2')
  135.                                 {
  136.                                     echo "<td style='background-color: beige;'>".$dbR2." (Seleccionada)</td>";
  137.                                 }
  138.                                 else
  139.                                 {
  140.                                     echo "<td>".$dbR2."</td>";
  141.                                 }
  142.                             echo "</tr>";
  143.                             echo "<tr>";
  144.                                 echo "<td>c</td>";
  145.                                 if (@$respuestas[$i]=='3')
  146.                                 {
  147.                                     echo "<td style='background-color: beige;'>".$dbR3." (Seleccionada)</td>";
  148.                                 }
  149.                                 else
  150.                                 {
  151.                                     echo "<td>".$dbR3."</td>";
  152.                                 }
  153.                             echo "</tr>";
  154.                             $i += 1;
  155.                         }
  156.                     }
  157.                     if (@$acum==0)
  158.                     {
  159.                         $nota=0;
  160.                     }
  161.                         else
  162.                         {
  163.                             $nota=($acum/$iNumReg)*5;
  164.                         }
  165.                         $tematicaId=$row_Recordset2['tematicaId'];
  166.                         $matriculaId=$row_Recordset2['matriculaId'];
  167.                         $estudianteId=$row_Recordset2['estudianteId'];
  168.                        
  169.                        
  170.                         @$sql = "insert into notas values ('','$estudianteId','$tematicaId','$nota','$matriculaId')";
  171.                         if(mysql_query ($sql))
  172.                         {
  173.                             echo "Evaluacion enviada";
  174.                             echo "<br/><br/>";
  175.                         }
  176.                         echo "Tu nota final es de ".$nota;
  177.                        
  178.                     }
  179.                  echo "<tr><br/><br/>";
  180.                     if (@$show=='0')
  181.                     {
  182.                         echo "<td><br><br></td><td style='text-align: center;'><input name='submit' type='submit' value='Enviar evaluacion'<a class='button white' href='#'></a></td>";
  183.                        
  184.                     }
  185.                     else
  186.                     {
  187.                         echo "<td><br><br></td><td style='text-align: center;'><a href='cursos_matriculados.php?tematicasId=".$tematicaId."'>Salir</a></td>";
  188.                     }
  189.                 echo "</tr>";
  190.             ?>
  191.         </form>
  192.     </table>
  193.  <br/>
  194.  
  195.   <a href="curso_desarrollo.php?tematicasId=<?php echo $row_Recordset1['tematicasId']; ?>">Regresar</a>

Última edición por diegodelpiero; 10/07/2015 a las 11:51