test.php 假如有50条记录,被分成5页显示。在第一页选择后点击下一页进行选择、再返回上一页时前面所做的选择全没了
- -! 再点击下一页时后一页的选择也没了... 网上有说用COOKIE的,有说用SESSION的....无奈自个儿还是整不出来!也没有哪位高手帮忙解决下,最好给个示例~谢谢囖!<form action="test2.php" method="post">
<table>
<?php
require_once("page.class.php");//分页类
$db=mysql_connect("localhost","root","123456");
mysql_select_db("test",$db); $pagesize=10;
$page=new Pager($pageSize,&$db,$sql,$pageNo,10);//$PageSize->每页要显示的数量,&$db->数据库连接资源,$sql->SQL语句,$pageNo->当前第几页,10->10页换行
$currentPage=$page->getStartNo();//起始页
$totalPage=$page->getPageCount();//总页数
$query=mysql_query("select * from question limit $currentPage,$pagesize");
while($rs=mysql_fetch_array($query)){
?>
<tr>
<td>
问题:<?php echo $rs['question'];?>
</td>
</tr>
<tr>
<td>
<input type="radio" name="<?php echo $rs['id'];?>" value="A">A.<?php echo $rs['option1'];?>
</td>
</tr>
<tr>
<td>
<input type="radio" name="<?php echo $rs['id'];?>" value="B">A.<?php echo $rs['option2'];?>
</td>
</tr>
<tr>
<td>
<input type="radio" name="<?php echo $rs['id'];?>" value="C">A.<?php echo $rs['option3'];?>
</td>
</tr>
<tr>
<td>
<input type="radio" name="<?php echo $rs['id'];?>" value="D">A.<?php echo $rs['option4'];?>
</td>
</tr>
<?php
}//循环结束
$url="test.php?";
$page->subPageCss2($url);//分页
mysql_close();
?>
</table>
</form>
- -! 再点击下一页时后一页的选择也没了... 网上有说用COOKIE的,有说用SESSION的....无奈自个儿还是整不出来!也没有哪位高手帮忙解决下,最好给个示例~谢谢囖!<form action="test2.php" method="post">
<table>
<?php
require_once("page.class.php");//分页类
$db=mysql_connect("localhost","root","123456");
mysql_select_db("test",$db); $pagesize=10;
$page=new Pager($pageSize,&$db,$sql,$pageNo,10);//$PageSize->每页要显示的数量,&$db->数据库连接资源,$sql->SQL语句,$pageNo->当前第几页,10->10页换行
$currentPage=$page->getStartNo();//起始页
$totalPage=$page->getPageCount();//总页数
$query=mysql_query("select * from question limit $currentPage,$pagesize");
while($rs=mysql_fetch_array($query)){
?>
<tr>
<td>
问题:<?php echo $rs['question'];?>
</td>
</tr>
<tr>
<td>
<input type="radio" name="<?php echo $rs['id'];?>" value="A">A.<?php echo $rs['option1'];?>
</td>
</tr>
<tr>
<td>
<input type="radio" name="<?php echo $rs['id'];?>" value="B">A.<?php echo $rs['option2'];?>
</td>
</tr>
<tr>
<td>
<input type="radio" name="<?php echo $rs['id'];?>" value="C">A.<?php echo $rs['option3'];?>
</td>
</tr>
<tr>
<td>
<input type="radio" name="<?php echo $rs['id'];?>" value="D">A.<?php echo $rs['option4'];?>
</td>
</tr>
<?php
}//循环结束
$url="test.php?";
$page->subPageCss2($url);//分页
mysql_close();
?>
</table>
</form>
根据页面保存checkbox选择项,
如果返回上一次,取出保存的值,然后勾选选项.
可以用php,也可以用js勾选.
建议你先去看看session的教程,然后在去思考你这个问题。
<input type="radio" name="gender" value="F" <?php if ($gender == 'F') {echo 'checked="checked"';} ?>/>
session_start();
?>
<html>
<head><title>选择</title></head>
<body>
<form action = "test1.php" method = "post">
<input type="radio" name="fruit" value = "a" <?php echo $_SESSION['a'];?>>a<br>
<input type="radio" name="fruit" value = "b" <?php echo $_SESSION['b'];?>>b<br>
<input type="radio" name="fruit" value = "c" <?php echo $_SESSION['c'];?>>c<br>
<input type="submit" value="提交">
</form>
<a href="test1.php">下一页</a>
</body>
</html>
<?
session_start();
if($_POST['fruit']=='a')
{
$_SESSION['a']='checked';
unset($_SESSION['b']);
unset($_SESSION['c']);
echo 'a';
}
if($_POST['fruit']=='b')
{
$_SESSION['b']='checked';
unset($_SESSION['a']);
unset($_SESSION['c']);
echo 'b';
}
if($_POST['fruit']=='c')
{
$_SESSION['c']='checked';
unset($_SESSION['a']);
unset($_SESSION['b']);
echo 'c';
}
?><html>
<head><title></title></head>
<body>
test1.php<br>
<a href="test.php">上一页</a>
</body>
</html>试一下这个吧,同一个radion里的name必须是相同的
还有一种方法是在转向下一页时用js保存cookie,最后再用程序取得cookie值处理