2014-03-06 61 views
0

我正在进行测验。我在一页上看到所有问题,但我不想那样。我只想要第一个问题。点击按钮后,我想要第二个问题。我怎样才能做到这一点?这里是我的代码:显示while循环的一行

$qry=mysql_query("select `id`,`question` from `paper_details` where `paper_id`='$id'") or die(mysql_error()); 
    $num_rw= mysql_num_rows($qry); 
    while($f=mysql_fetch_assoc($qry)) 
    { 
     $q2=mysql_query("select `id`,`que`,`unique_id`,`image` from `que_master` where `id`='".$f['question']."'") or die(mysql_error()); 
     $f2=mysql_fetch_row($q2); 
     $i=$pid;?> 
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="4" class="form_border" id="form_table"> 
    <tr> 
    <th width="3%" rowspan="2" align="left" valign="top" class="form_label"></th> 
    <th width="5%" height="27" align="left" valign="top" class="form_label">Que<?php echo $i;?> : </th> 
    <th width="92%" align="left" valign="top" class="form_label"> <?php echo $f2[1]; if($f2[3]!=""){?> 
    <img src="admin/que_image/<?php echo $f2[3];?>" border="noborder" width="20px" height="20px"/><?php }?> 
    <input type="hidden" id="que_id" name="que_id" value="<?php echo $f2[0];?>"/> 
    </th> 
    </tr> 
    <tr> 
    <th height="78" align="left" valign="top" class="form_label">Ans : </th> 
    <td align="left" valign="top" style="line-height:2.0em;"> 
    <input type="hidden" id="id" name="id" value="<?php echo $id;?>"/> 
    <input type="hidden" id="pid" name="pid" value="<?php echo $pid+1;?>"/> 
    <input type="hidden" id="num_raw" name="num_raw" value="<?php echo $num_rw;?>"/> 
    <input type="hidden" id="time" name="time" value="<?php echo $time;?>" /> 
    <input type="hidden" id="que_id" name="que_id" value="<?php echo $f2[0];?>" /> 
    <?php 

     $q3=mysql_query("select `id`,`ans`,`ans_img` from `ans_master` where `unique_id`='$f2[2]'") or die(mysql_error()); 

     while($f3=mysql_fetch_row($q3)){ 
     ?> 
       <input type="radio" value="<?php echo $f3[0]; ?>" name="ans" id="ans"><?php echo $f3[1]; ?><?php if($f3[2]!=""){?> 
        <img src="admin/ans_image/"<?php echo $f3[2];?>" border="noborder" width="20px" height="20px"/> 

     <?php } 
       }} 
      ?> 
</td> 
    </tr> 
    <tr> 
    <th height="33" align="left" valign="middle" class="form_label">&nbsp;</th> 
    <th colspan="2" align="left" valign="middle" class="form_label"> 
    <input type="submit" name="Submit" value="Next >" /> 

请帮帮我。

+3

你必须处理这个使用javascript – Populus

+0

@Populus - 嗯,不一定。处理它没有整页刷新?那么是的,JavaScript需要一定剂量的AJAX。我认为['LIMIT'和'OFFSET'](https://dev.mysql.com/doc/refman/5.0/en/select.html#idm47039154543520)可以用于数据库端。 –

+0

使用javascript更容易,因此您只需处理显示和隐藏问题,然后一次提交所有内容,而不必在所有问题保存完毕后才能提交答案。 – Populus

回答

0

如果我理解正确,您希望有一个单页面应用程序来运行测验。
为此,您可以在jQuery中使用ajax请求。

否则,您可以为每个问题制作一个单独的页面。