Tema: examen web
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/12/2012, 15:51
materialesanfra
 
Fecha de Ingreso: diciembre-2012
Mensajes: 2
Antigüedad: 11 años, 3 meses
Puntos: 0
Mensaje examen web

hola tengo un codigo para hacer un examen en php solo que me falta que me sume las preguntas correctas y no se como tomar la variable.

les dejo el codigo a ver si me puede alguien ayudar

aca me valida las preguntas

<?
session_start();
include_once "conectar.php";
$c=$_POST['cur'];
?>
<style>
* {font-size:10px}
</style>
<br>

<form action="resultados.php" method="post"><?
// sacamos X preguntas al hazar
$hacer_trampa=1; // 1 hacer trampa 0 no hacer trampa
$numero_de_preguntas=10; //numero de preguntas que se sacarán al hazar

$sql="SELECT * FROM preguntas where curso='$c' ORDER BY RAND() LIMIT $numero_de_preguntas";
if ($sql=mysql_query($sql))
{
$a=0;
while($assoc=mysql_fetch_assoc($sql))
{
$pregunta[]=$assoc['pregunta'];
$respuesta[$a][0]=$assoc['correcta'];
$respuesta[$a][1]=$assoc['incorrecta1'];
$respuesta[$a][2]=$assoc['incorrecta2'];
$respuesta[$a][3]=$assoc['incorrecta3'];
$_SESSION['id_pregunta'][$a]=$assoc['id'];
$a++;

}
mysql_free_result($sql);
foreach($pregunta as $indice=>$valor)
{
// Mezclamos y sacamos nuevo id de correcta
$arrayAleatorio = range(0, 3);
shuffle($arrayAleatorio);
$nuevoIdCorrecta=array_search("0",$arrayAleatorio) ;
$_SESSION['array'][$indice]=$arrayAleatorio;
echo "<b>$valor</b><br>\n";
foreach($arrayAleatorio as $indice1=>$valor1)
echo "<input type=\"radio\" name=\"Pregunta".$indice."\" value=\"".$valor1."\" />". $respuesta[$indice][$arrayAleatorio[$valor1]] . ( ( $valor1 == $nuevoIdCorrecta && $hacer_trampa) ? " 1" : " incorrecta" ) . "<br />\n";
}
}

?>
<INPUT TYPE="submit" name="respuestas" value="Respuestas">



Aca me arma una matriz con color de las correctas y yo quiero que me sume la cantidad para evaluar la nota.

<?
session_start();
// conexion db
include_once "conectar.php";
?>
<style>
* {font-size:12px}
.acierto{border:2px solid #336699;background:#eeeeff;text-align:center}
.fallo{border:2px solid #996633;background:#ffeeee;text-align:center}
.acierto1{background:#eeeeff;text-align:center}
.fallo1{background:#ffeeee;text-align:center}
.pregunta{background:#eeffee;text-align:center}
</style>

<table border="1" align="center" width="100%">
<tr>
<th>Pregunta</th>
<th>Correcta</th>
<th>Contestada bien</th>

</tr><?



if (is_array($_SESSION['id_pregunta']))
foreach ($_SESSION['id_pregunta'] as $key=>$value)

{
$sql="SELECT * FROM preguntas WHERE id=".$value;

if ($sql=mysql_query($sql))

{?><tr><?
$assoc=mysql_fetch_assoc($sql);
$envio=$_SESSION['array'][$key];
$correcta=array_search("0",$envio);
@$value1=$_POST['Pregunta'.$key];



print "<td class=\"pregunta\"><b><tt>".$assoc['pregunta']."</b></tt></td>\n";


print "<td".( ( array_search("0",$envio) == $value1 && $value1!="") ? " class=\"acierto\"" : " class=\"acierto1\"" )."><tt>".$assoc['correcta']
. "</tt></td>\n";



print "<td".( ( array_search("1",$envio) == $value1 && $value1!="" ) ? " class=\"fallo\"" : " class=\"fallo1\"" )."><tt>".$assoc['incorrecta1']. "</tt></td>\n";
print "<td".( ( array_search("2",$envio) == $value1 && $value1!="" ) ? " class=\"fallo\"" : " class=\"fallo1\"" )."><tt>".$assoc['incorrecta2']. "</tt></td>\n";
print "<td".( ( array_search("3",$envio) == $value1 && $value1!="" ) ? " class=\"fallo\"" : " class=\"fallo1\"" )."><tt>".$assoc['incorrecta3']. "</tt></td>\n";
?></tr><?


}

}
echo count ($assoc['correcta']);

session_destroy();
?>
</table>
<br><br>
<table border="1" align="center" width="50%">
<tr>
<td class="acierto">&nbsp;&nbsp;</td><td>Respuesta enviada y acertada</td>
</tr>
<tr>
<td class="fallo">&nbsp;&nbsp;</td><td>Respuesta enviada y fallada</td>
</tr>
<td class="acierto1">&nbsp;&nbsp;</td><td>Respuesta correcta</td>
</tr>
<tr>
<td class="fallo1">&nbsp;&nbsp;</td><td>Respuesta incorrecta</td>
</tr>
</table>

Gracias por la ayuda llevo mas de una semana y no le encuentro la vuelta.