0
  ## Keep Radio Button Value after Next/Prev page .. ##

这是学生在线考试

 if(!isset($_GET['start'])){
 $_GET['start'] = "undefined";
 }
$start=$_GET['start'];          /*To take care global variable if OFF*/
if(!($start > 0)) {             /*This variable is set to zero for the first page*/
$start = 0;
}

$startpos = ($start -0);               
$limit = 1;
// No of records to be shown per page.
$currentpos = $startpos + $limit; 
$back = $startpos - $limit; 
$next = $startpos + $limit; 

    $countquery=" SELECT * FROM quiz  ";
     $countresult=mysql_query($countquery);
     echo mysql_error();
    $totalrecords=mysql_num_rows($countresult);

      //$quiz_table = mysql_query("select * from quiz Limit 1");
      ?>
     <form method="POST"  action="" onclick="">
     <table>

     <?php

      $quiz_table=" SELECT * FROM quiz ORDER BY qid limit $startpos, $limit ";
      $result=mysql_query($quiz_table);
      echo mysql_error();

       while ($row = mysql_fetch_array($result)) 
       { 
       ?>
        <tr>
          <td><?php echo "$row[qid]"; ?></td>

          <td><?php echo "$row[Question]"; ?></td>
          </tr>
          <tr>

       <td><input type="radio" name="a" id="a" value="a"/>   <?php echo "$row[opt1]"; ?></td>
      <td><input type="radio" name="a" id="a" value="b"/>   <?php echo "$row[opt2]"; ?></td>
      <td><input type="radio" name="a" id="a" value="c"/>   <?php echo "$row[opt3]"; ?></td>
        <td><input type="radio" name="a" id="a" value="d"/>   <?php echo "$row[opt4]"; ?></td>

       </tr>
      <tr>
     <td><!--<input type="submit" name="smt" value="check"/>-->
      <?php
     if($back >=0) { 
       print "<a href='onlineexam.php?start=$back'><font face='Verdana' size='2'><input type='button' name='prev' value='PREV'></font></a>"; 
        }    

        if($currentpos < $totalrecords) {
                     ## Keep Radio Button Value after Next/Prev page .. ##
      print "<a href='onlineexam.php?start=$next'><font face='Verdana' size='2'><input type='button' name='nxt' value='NEXT'></font></a>"; 
          }
          ?></td>
       <td><input type="submit" name="smt" value="Finish"/></td>
        </tr>
        <?php
       }

      $quiz_table="SELECT * from quiz";

    $result=mysql_query($quiz_table);

   while ($row = mysql_fetch_array($result))   
  {  
   $id=$row['qid'];
   $ques=$row['Question'];  
  $op1=$row['opt1'];
  $op2=$row['opt2'];
  $op3=$row['opt3'];
  $op4=$row['opt4']; 
  $crt=$row['woptcode']; 

   if(isset($_POST['smt'])){
      $ans= $_POST['a'];
   if(isset($_POST['a'])){

     if($crt == $ans ){
     $mark=0;
     $mark=$mark+1;

     mysql_query("INSERT INTO  stuans(qid,Question,opt1,opt2,opt3,opt4,woptcode,stuanswer,mark)VALUES('$id','$ques','$op1','$op2','$op3', '$op4','$crt','$ans','$mark')");   
   }  else{
  $mark=0;
  mysql_query("INSERT INTO stuans(qid,Question,opt1,opt2,opt3,opt4,woptcode,stuanswer,mark)VALUES('$id','$ques','$op1','$op2','$op3', '$op4','$crt','$ans','$mark')");   
     }
    } 
   }  

   }
      ..THANKS..
4

1 回答 1

0

您可以使用该checked属性。

<input type="radio" checked>

因此,如果您有一些变量(布尔值),$opt1, $opt2, $opt3, $opt4,那么您可以执行类似的操作:

<input type="radio" name="opt1" <?php if ($opt1) echo "checked"; ?> />
<input type="radio" name="opt2" <?php if ($opt2) echo "checked"; ?> />
<input type="radio" name="opt3" <?php if ($opt3) echo "checked"; ?> />
<input type="radio" name="opt4" <?php if ($opt4) echo "checked"; ?> />
于 2013-02-19T10:16:14.677 回答