我试图从我的表获取记录,但它一次显示所有记录。我想要查看单行数据。单击下一个按钮后,它将跳转到下一行。我们如何才能做到这一点?
<?php include("conect.php"); ?>
<?php
session_start();
if($_SESSION['u_name'==''])
{
echo "log in failed";
echo '<script> window.locaion="index.php";</script>';
}?>
<?php
$query=mysql_query("select * from question_paper ");
$i=1;
while($res= mysql_fetch_array($query))
{
$id=$row['main_id'];
$question=$res['question'];
$optionA=$res['option1'];
$optionB=$res['option2'];
$optionC=$res['option3'];
$optionD=$res['option4'];
?>
<html>
<head><title>exam</title></head>
<body>
<form name="student_form" action="" method="post">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="36" colspan="2" bgcolor="#85A157"> (<?php echo $i;?>)<?php echo $question;?> </td>
</tr>
<tr>
<td colspan="2"><table width="100%" height="64" border="2" cellpadding="0" cellspacing="0" bordercolor="#A6BF79">
<tr>
<td height="32" width="50%"><input type="radio" name="RadioGroup<?php echo $i;?>" value="<?php echo $optionA;?>" id="optionA" />
<?php echo $optionA;?></td>
<td width="50%"><input type="radio" name="RadioGroup<?php echo $i;?>" value="<?php echo $optionC;?>" id="optionC" />
<?php echo $optionC;?></td>
</tr>
<tr>
<td height="32" width="50%"><input type="radio" name="RadioGroup<?php echo $i;?>" value="<?php echo $optionB;?>" id="optionB" />
<?php echo $optionB;?></td>
<td width="50%"><input type="radio" name="RadioGroup<?php echo $i;?>" value="<?php echo $optionD;?>" id="optionD" />
<?php echo $optionD;?></td>
</tr>
</table></td>
</tr>
</table>
<?php
$i=$i+1;
}
?>
<?php
$records = mysql_num_rows($query);
if($records!=0)
{
?>
<input type="submit" name="button" id="button" value="Submit" />
<?php
}
?>
</form>
</body>
</html>
最好使用分页,并与select查询使用限制和分页请参阅以下链接http://www.tutorialspoint.com/php/mysql_paging_php.htm
$sql="SELECT * FROM tbl_name
WHERE id>= (SELECT FLOOR(MAX(id) * RAND()) FROM tbl_name
) ORDER BY id LIMIT $no_of_question_you_want SELECT ";