热搜:NVER node 开发 php

PHP分页问题,请大神现身!分页代码页书显示正确,但每页显示重复内容。

2024-07-27 21:35:02
PHP分页问题,请大神现身!分页代码页书显示正确,但每页显示重复内容。


数据库内共有1287条记录,设置每页显示1000条,每行显示9条。

但结果一页里就把所有记录1~1287都显示了,第二页也是1~1287.
分页数是正确的2页,

哪里出了问题请各位帮忙看下代码,十分感谢!
代码如下:

<?php $page = $_GET["page"]; function Page($rows,$page_size){ global $page,$select_from,$select_limit,$pagenav; $page_count = ceil($rows/$page_size); if($page <= 1 || $page == '') $page = 1; if($page >= $page_count) $page = $page_count; $select_limit = $page_size; $select_from = ($page - 1) * $page_size.','; $pre_page = ($page == 1)? 1 : $page - 1; $next_page= ($page == $page_count)? $page_count : $page + 1 ; $pagenav .= "第 $page/$page_count 页 共 $rows 条记录 "; $pagenav .= "首页 "; $pagenav .= "前一页 "; $pagenav .= "后一页 "; $pagenav .= "末页"; $pagenav.=" 跳到\n"; for($i=1;$i<=$page_count;$i++){ if($i==$page) $pagenav.="\n"; else $pagenav.="\n"; } } $conn = mysql_connect('127.0.0.1:8889', 'root', 'root');mysql_select_db('test3', $conn);$rows = mysql_num_rows(mysql_query("select * from cp")); ///@@这段帮你添加的	$limit_start=($page-1)*1000;	$s = "select * from cp limit $limit_start,1000"; ///@@$sql="select * from cp";$r = mysql_query($s);Page($rows,1000); //$s = "select * from cp limit 0,1000"; //$rst = mysql_query($s); //$row = mysql_fetch_array($rst); ?><?php   $k=1;  while($rs = mysql_fetch_assoc($r))  {    $color=$rs["count"] >= "3"?"#999999":"white";    echo $k%9==1?"":"";?>   <?php   echo $k%9==0?"":"";   $k++;  } ?><?phpecho $pagenav; ?>
<?php echo $rs["id"];?> <?php echo $rs["cp"];?> <?php echo $rs["count"];?>

$sql="select * from cp limit ".($page-1)*1000.",1000";$r = mysql_query($sql);Page($rows,1000); //$s = "select * from cp limit 0,1000"; //$rst = mysql_query($s); //$row = mysql_fetch_array($rst); 上面三行你都没用到,注释掉$sql修改一下,你下面循环用到的是$r对应的sql语句所以一直是一样的

$sql="select * from cp limit ".($page-1)*1000.",1000";$r = mysql_query($sql);Page($rows,1000); //$s = "select * from cp limit 0,1000"; //$rst = mysql_query($s); //$row = mysql_fetch_array($rst); 上面三行你都没用到,注释掉$sql修改一下,你下面循环用到的是$r对应的sql语句所以一直是一样的



$cnt = ($page-1)*1000;$sql="select * from cp limit $cnt,1000";

<?php $page = $_GET["page"]; function Page($rows,$page_size){ global $page,$select_from,$select_limit,$pagenav; $page_count = ceil($rows/$page_size); if($page <= 1 || $page == '') $page = 1; if($page >= $page_count) $page = $page_count; $select_limit = $page_size; $select_from = ($page - 1) * $page_size.','; $pre_page = ($page == 1)? 1 : $page - 1; $next_page= ($page == $page_count)? $page_count : $page + 1 ; $pagenav .= "第 $page/$page_count 页 共 $rows 条记录 "; $pagenav .= "首页 "; $pagenav .= "前一页 "; $pagenav .= "后一页 "; $pagenav .= "末页"; $pagenav.=" 跳到