请问我想用php做翻页以后,上一页checkbox选中状态还存在,用session怎么做啊!求代码!谢谢! 代码如下 10
<?php$link=MySQL_connect('localhost','root','auto');mysql_select_db('test');$Page_siz...
<?php
$link=MySQL_connect('localhost','root','auto');
mysql_select_db('test');
$Page_size=3;
$result=mysql_query('select * from testcase');
$count = mysql_num_rows($result);
$page_count = ceil($count/$Page_size);
$init=1;
$page_len=7; //页长?
$max_p=$page_count;
$pages=$page_count;
//判断当前页码
if(empty($_GET['page'])||$_GET['page']<0){
$page=1;
}else {
$page=$_GET['page'];
}
$offset=$Page_size*($page-1);
$sql="select * from testcase limit $offset,$Page_size";
$page_len = ($page_len%2)?$page_len:$pagelen+1;//页码个数
$pageoffset = ($page_len-1)/2;//页码个数左右偏移量
$key='<div>';
if($page!=1){
$key.="<a href=\"".$_SERVER['PHP_SELF']."?page=1\">首页</a>"; //第一页
$key.="<a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\">上一页</a>"; //上一页
}else {
$key.="首页 ";//第一页
$key.="上一页"; //上一页
}
$key.="<span> $page/$pages</span> "; //第几页,共几页
if($pages>$page_len){
//如果当前页小于等于左偏移
if($page<=$pageoffset){
$init=1;
$max_p = $page_len;
}else{//如果当前页大于左偏移
//如果当前页码右偏移超出最大分页数
if($page+$pageoffset>=$pages+1){
$init = $pages-$page_len+1;
}else{
//左右偏移都存在时的计算
$init = $page-$pageoffset;
$max_p = $page+$pageoffset;
}
}
}
if($page!=$pages){
$key.=" <a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\">下一页</a> ";//下一页
$key.="<a href=\"".$_SERVER['PHP_SELF']."?page={$pages}\">尾页</a>"; //最后一页
}else {
$key.="下一页 ";//下一页
$key.="尾页"; //最后一页
}
$key.='</div>';
?>
<div align="center"><?php echo $key?></div>
<?php
$collapse=1;
$result=mysql_query($sql,$link);
while($row=mysql_fetch_array($result)){
$collapse+=1;
echo
"<li class='unread'>"."<span class='checkbox-custom'>"."<input type='checkbox' name='checkbox[]' id='mailInbox'>".
"<label for='mailInbox'>"."</label>"."</span>"."<a class='from' data-toggle='collapse' href=#'$collapse' style='font-size:15px; font-weight: bold;'>".
nl2br($row['test_title'])."</a>"."<div class='pull-right'>"."<i class='fa fa-paperclip'>"."</i>"." 入库时间:".nl2br($row['add_time'])."</div>".
"<div>"."<span class='action'>"."<i class='fa fa-star'>"."</i>"."</span>"." xt"."</div>".
"</li>"."<div id='$collapse' class='panel-collapse collapse'>"."<div class='panel-body'>"."测试用例内容"."</div>"."</div>";
}
?> 展开
$link=MySQL_connect('localhost','root','auto');
mysql_select_db('test');
$Page_size=3;
$result=mysql_query('select * from testcase');
$count = mysql_num_rows($result);
$page_count = ceil($count/$Page_size);
$init=1;
$page_len=7; //页长?
$max_p=$page_count;
$pages=$page_count;
//判断当前页码
if(empty($_GET['page'])||$_GET['page']<0){
$page=1;
}else {
$page=$_GET['page'];
}
$offset=$Page_size*($page-1);
$sql="select * from testcase limit $offset,$Page_size";
$page_len = ($page_len%2)?$page_len:$pagelen+1;//页码个数
$pageoffset = ($page_len-1)/2;//页码个数左右偏移量
$key='<div>';
if($page!=1){
$key.="<a href=\"".$_SERVER['PHP_SELF']."?page=1\">首页</a>"; //第一页
$key.="<a href=\"".$_SERVER['PHP_SELF']."?page=".($page-1)."\">上一页</a>"; //上一页
}else {
$key.="首页 ";//第一页
$key.="上一页"; //上一页
}
$key.="<span> $page/$pages</span> "; //第几页,共几页
if($pages>$page_len){
//如果当前页小于等于左偏移
if($page<=$pageoffset){
$init=1;
$max_p = $page_len;
}else{//如果当前页大于左偏移
//如果当前页码右偏移超出最大分页数
if($page+$pageoffset>=$pages+1){
$init = $pages-$page_len+1;
}else{
//左右偏移都存在时的计算
$init = $page-$pageoffset;
$max_p = $page+$pageoffset;
}
}
}
if($page!=$pages){
$key.=" <a href=\"".$_SERVER['PHP_SELF']."?page=".($page+1)."\">下一页</a> ";//下一页
$key.="<a href=\"".$_SERVER['PHP_SELF']."?page={$pages}\">尾页</a>"; //最后一页
}else {
$key.="下一页 ";//下一页
$key.="尾页"; //最后一页
}
$key.='</div>';
?>
<div align="center"><?php echo $key?></div>
<?php
$collapse=1;
$result=mysql_query($sql,$link);
while($row=mysql_fetch_array($result)){
$collapse+=1;
echo
"<li class='unread'>"."<span class='checkbox-custom'>"."<input type='checkbox' name='checkbox[]' id='mailInbox'>".
"<label for='mailInbox'>"."</label>"."</span>"."<a class='from' data-toggle='collapse' href=#'$collapse' style='font-size:15px; font-weight: bold;'>".
nl2br($row['test_title'])."</a>"."<div class='pull-right'>"."<i class='fa fa-paperclip'>"."</i>"." 入库时间:".nl2br($row['add_time'])."</div>".
"<div>"."<span class='action'>"."<i class='fa fa-star'>"."</i>"."</span>"." xt"."</div>".
"</li>"."<div id='$collapse' class='panel-collapse collapse'>"."<div class='panel-body'>"."测试用例内容"."</div>"."</div>";
}
?> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询