Para ello me construi 2 tablas (preguntas-respuestas)
donde las opciones de respuestas estan apuntando a un valor de calificación, para tal efecto solicito me selecciones una con tipo radio pero no se como debo guardas los datos para despues recuperarlos en otra pagina, ademas de validar que exista solo una alternativa de respuesta marcada por cada pregunta.
Código PHP:
<form name="Califica" method="post" action="prueba.php" OnSubmit="return validar(this);">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?
include("config.php");
$sql="select * from preguntas order by id asc";
$pregunta = mysql_query($sql,$db) or die (mysql_error());
$registros= mysql_num_rows($pregunta);
echo "Preguntas: ".$registros;
while($reg=mysql_fetch_array($pregunta))
{
// selecciono todas las preguntas
$npreg=$reg['id'];
$preg=$reg['pregunta'];
?>
<table width=100% border=0>
<tr>
<td colspan=3 id=texto><? echo $npreg."-". $preg; ?></td>
</tr>
<tr>
<td width=20%> </td>
<td width=60%>
<table width=100% border=0
<?
//Selecciono las respuestas para cada una de las preguntas
$sq="select * from respuestas where id_preg = '$npreg' order by id desc";
$respuesta = mysql_query($sq,$db) or die (mysql_error());
while($rg=mysql_fetch_array($respuesta))
{
$idre=$rg['id'];
$idpr=$rg['id_preg'];
$resp=$rg['respuesta'];
$punt=$rg['puntos'];
?>
<tr>
<td width=80% id=texto><? echo $resp; ?></td>
<td width=20%><input type=radio name="test<? echo $npreg;?>"
value="<? echo $idpr."-".$idre."-".$punt;?>"></td>
</tr>
<?
}
?>
</table>
</td>
<td width=20%> </td>
</tr>
</table>
<?
}
?>
<table width=100% border=1 cellspacing=0 cellpadding=2>
<tr>
<td width=100% align=center><input type=submit value="Calificar"><input type=hidden name=reg value="<? echo $registros; ?>"></td>
</tr>
</table>
</form>
*************
*** validar() ***
*************
<script>
function validar()
{
for ( var i = 0; i <= 3; i++ )
{
if (!validarBotonRadio(i))
//alert("1")
{
alert("no ha terminado la Evaluación" ) ;
return false;
}
}
alert("Evaluacion Completa" );
return true;
}
function validarBotonRadio(i)
{
//alert("2")
x = document.theForm["test"+i];
//alert(document.theForm["test"+i+])
for ( k = 0; k < x.length; k++ )
//alert("test"+i+k)
{
if ( x[k].checked )
{
alert("OIOIOI")
return true;
}
}
return false;
}
</script>
Hasta el momento las variables test1, test2 y test3 existen ¿Como muestro los valores que recupero?