Hola, estoy editando un script para hacer preguntas y respuestas aleatorias, el cual esta funcionando, lo que no funciona son las respuestas por que no puedo hacer que se emparejen y todas las respuestas son la alternativa a.
 
todo se maneja con una sola base de datos con los siguientes campos
 
BD:
 
sno questions                a                           b                           c                           d                correctans
1   PREGUNTA 1   CORRECTA   INCORRECTA   INCORRECTA   INCORRECTA   a
2   PREGUNTA 2   INCORRECTA   INCORRECTA   INCORRECTA   CORRECTA   d
3   PREGUNTA 3   INCORRECTA   INCORRECTA   CORRECTA   INCORRECTA   c
4   PREGUNTA 4   INCORRECTA   CORRECTA   INCORRECTA   INCORRECTA   b
5   PREGUNTA 5   INCORRECTA   CORRECTA   INCORRECTA   INCORRECTA   b
 
 
el codigo index.php que se utiliza es el siguiente
 
<?php
session_start();
require("connect.php");
// $nombre = $row['nombre']; 
$arr = range('a','z');
$num = range(1,2);
 
if(!isset($_POST['sno'])){
   $sno=1;   
 
$qusid = range(1,5);
$qus = array_rand($qusid);
 
$_SESSION['qid'] = $qus;
 
$str = $arr[array_rand($arr)].$num[array_rand($num)].$arr[array_rand($arr)].$arr[array_rand($arr)].$num[array_rand($num)];
 
$_SESSION['table'] = str_shuffle($str);
mysql_query("create table if not exists ".$_SESSION['table']."(sno int(11) null auto_increment, usrans varchar(11) not null, qid int(11), primary key(sno));") or die(mysql_error());
 
}else{
   $sno=$_POST['sno'];
   $sno++;   
   $ans=$_POST['op'];
 
   $s=$_POST['s'];
 
   $qusid = range(1,5);
   $qus = array_rand($qusid);
 
   mysql_query("insert into ".$_SESSION['table']." values(null, '$ans', '$s');");
   if($sno==2){
   header("Location: results.php");
   }
}
 
?>
<html>
<head>
<title>.:Quiz:.</title>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>
<div id="main">
<?php
 
$query = mysql_query("select * from qb where sno=$qus") or die(mysql_error());
$fetch = mysql_fetch_assoc($query) or die(mysql_error());
 
?>
<form name="fm" id="fm" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" id="sno" name="sno" value="<?php echo $sno; ?>" />
 
<?php
 
echo "<table border='2' cellpadding='15'>";
echo "<tr><td>".$fetch['question']."</tr></td>";
echo " <tr><td colspan='2'>A) "."<input type='radio' name='op' id='op' value='a'>".$fetch['a']."</tr></td>";
echo " <tr><td colspan='2'>B) "."<input type='radio' name='op' id='op' value='b'>".$fetch['b']."</tr></td>";
echo " <tr><td colspan='2'>C) "."<input type='radio' name='op' id='op' value='c'>".$fetch['c']."</tr></td>";
echo " <tr><td colspan='2'>D) "."<input type='radio' name='op' id='op' value='d'>".$fetch['d']."</tr></td>";
 
?>
 
<tr><td colspan='2'><input type="hidden" name="s" id="s" value="<?php echo $fetch['sno']; ?>"><input type="submit" name="sb" id="sb"/></td></tr>
</table>
</form>
</div>
</body>
</html>
 
De la base de datos saca las 5 primeras respuestas solo mostrando 1 para responder y luego va al archivo results.php que es el siguiente
 
<?php
session_start();
?>
<html>
<head>
<title>.:Quiz Results:.</title>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>
<div id="main">
<?php
 
require("connect.php");
 
 
$query = mysql_query("select * from ".$_SESSION['table']) or die(mysql_error());
$cc=0;
while($fetch = mysql_fetch_assoc($query)){
   $query_q = mysql_query("select correctans from qb where sno=".$fetch['sno']);
   $fetch_q = mysql_fetch_assoc($query_q);
   if($fetch['usrans']==$fetch_q['correctans']){
         $cc+=1;
   }
}
if($cc==1){
   echo "Respuesta Correcta!";   
}else{
   echo "Respuesta Incorrecta!";
}
 
echo "<br />";
echo "<br />";
mysql_query("drop table ".$_SESSION['table']) or die("Error is droping!");
 
  echo "<p>Regresar al banco de preguntas <a href='index.php'>Click Here</a>.</p>";
 
?>
</div>
</body>
</html>
 
Lo que hace es igualar la respuesta marcada en el boton de opcion determinando el nombre de la columna y esta la compara con el valor correctans (de la base de datos) de la fila donde se extrajeron los datos y la compara si son iguales la marca como correcta, el detalle es que solo la opcion a la toma como correcta y no esta comparando 
   
 



