PHP paging about the problem, please show the big God! Pagination code page book is displayed correctly, but duplicates are displayed on each page

Source: Internet
Author: User
PHP paging problem, please the Big God appeared! The paging code page book is displayed correctly, but each page shows duplicate content.

A total of 1287 records in the database, set to show 1000 per page, each row shows 9.

But the results on the page 1~1287 all the records, and the second page is 1~1287.
The number of pages is the correct 2 pages,

Where is the problem please help to look at the code, thank you very much!
The code is as follows:
 $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 page Total $rows records";
$pagenav. = "Home";
$pagenav. = "Previous page";
$pagenav. = "Next page";
$pagenav. = "Last";
$pagenav. = "Jump to\ n ";for ($i =1; $i <= $page _count; $i + +) {if ($i = = $page) $pagenav. = "$i\ n ";else $pagenav. = "$i\ 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");$sql = "SELECT * from CP";$r = mysql_query ($sql);Page ($rows, 1000);$s = "SELECT * from CP limit 0,1000";$rst = mysql_query ($s);$row = Mysql_fetch_array ($rst);?> $k = 1;while ($rs = Mysql_fetch_assoc ($r)){$color = $rs ["Count"] >= "3"? " #999999 ":" White ";echo $k%9==1? "":"";?> echo $k%9==0? "":"";$k + +;}?> Echo $pagenav;?>------to solve the idea----------------------Is your query string $s? =? " Select?*?from?cp?limit?0, 1000 ";No matter what the $_get["page" is, the 0 will always be the same, of course, each page will show the same result.The starting offset of the query should be the number associated with $_get["page")For you the case is ($_get["page"]-1) * 1000------to solve the idea---------------------- $page = $_get["page"];function Page ($rows, $page _size) {Global $page, $select _from, $select _limit, $pagenav;$page _count = ceil ($rows/$page _size);if ($page <= 1------to solve the idea----------------------$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 page Total $rows records";$pagenav. = "Home";$pagenav. = "Previous page";$pagenav. = "Next page";$pagenav. = "Last";$pagenav. = "Jump to\ n ";
for ($i =1; $i <= $page _count; $i + +) {
if ($i = = $page) $pagenav. = "$i\ n ";
else $pagenav. = "$i\ 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");
@@ This section to help you add
$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);
?>



















$k = 1; while ($rs = Mysql_fetch_assoc ($r)) {$color = $rs ["Count"] >= "3"? " #999999 ":" White "; echo $k%9==1? " ":"";? > echo $k%9==0? " ":""; $k + +; }?> echo $pagenav;?>


------to solve the idea----------------------


$sql = "SELECT * from CP limit". ($page-1) *1000. ", 1000";
$r = mysql_query ($sql);




Three lines above you are useless, comment out
$sql modify the SQL statement that you used to iterate
So it's always the same.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.