PHP paging problem, please show up! The pagination code page is displayed correctly, but the duplicate content is displayed on each page.

Source: Internet
Author: User
PHP paging problem, please show up! The pagination code page is displayed correctly, but the duplicate content is displayed on each page. There are a total of 1287 records in the database, with 1000 records displayed per page and 9 records per line.

However, on the result page, all records are 1 ~ 1287 is displayed, and the second page is also 1 ~ 1287.
The number of pages is two correct pages,

Thank you very much for reading the code!
The code is as follows:
 = $ 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 $ rows records"; $ pagenav. = "homepage"; $ pagenav. = "previous page"; $ pagenav. = "next page"; $ pagenav. = "Last page"; $ pagenav. = "Jump\ N "; for ($ I = 1; $ I <= $ page_count; $ I ++) {if ($ I = $ page) $ pagenav. ="$ I\ N "; else $ pagenav. ="$ I\ N ";}}$ conn = mysql_connect ('2017. 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 "; $ rst = mysql_query ($ s); $ row = mysql_fetch_array ($ rst);?>
  = "3 "? "#999999": "white"; echo $ k % 9 = 1? "":" ";?>
     
     
  
  ":" "; $ K ++;}?>
                                                                                      Reply to discussion (solution)Your query string is $ s = "select * from cp limit ";No matter what $ _ GET ["page"] is, the 0 value will never change. of course, the same result is displayed on each page.The starting offset of the query should be a number related to $ _ GET ["page "].In your case ($ _ GET ["page"]-1) * 1000        Your query string is $ s = "select * from cp limit ";No matter what $ _ GET ["page"] is, the 0 value will never change. of course, the same result is displayed on each page.The starting offset of the query should be a number related to $ _ GET ["page "].In your case ($ _ GET ["page"]-1) * 1000It seems that the initial code is actually $ s = "select * from cp limit $ select_from, $ select_limit ";$ Select_from = ($ _ GET ["page"]-1) * 1000; the result is the same...     
  = $ 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 $ rows records"; $ pagenav. = "homepage"; $ pagenav. = "previous page"; $ pagenav. = "next page"; $ pagenav. = "Last page"; $ pagenav. = "Jump\ N "; for ($ I = 1; $ I <= $ page_count; $ I ++) {if ($ I = $ page) $ pagenav. ="$ I\ N "; else $ pagenav. ="$ I\ N ";}}$ conn = mysql_connect ('2017. 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"; // $ rst = mysql_query ($ s); // $ row = mysql_fetch_arr Ay ($ rst);?>
 
 
  = "3 "? "#999999": "white"; echo $ k % 9 = 1? "
  
  
     ":" ";?> 
     ":" "; $ K ++;}?>  
   

$ SQL = "select * from cp limit ". ($ page-1) x 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); you have not used the above three lines. comment out $ SQL and modify it, the SQL statements corresponding to $ r are used in the following loop, so they are always the same.

$ SQL = "select * from cp limit ". ($ page-1) x 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); you have not used the above three lines. comment out $ SQL and modify it, the SQL statements corresponding to $ r are used in the following loop, so they are always the same.



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

 = $ 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 $ rows records"; $ pagenav. = "homepage"; $ pagenav. = "previous page"; $ pagenav. = "next page"; $ pagenav. = "Last page"; $ pagenav. = "Jump\ N "; for ($ I = 1; $ I <= $ page_count; $ I ++) {if ($ I = $ page) $ pagenav. ="$ I\ N "; else $ pagenav. ="$ I\ N ";}}$ conn = mysql_connect ('2017. 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"; // $ rst = mysql_query ($ s); // $ row = mysql_fetch_arr Ay ($ rst);?>
  = "3 "? "#999999": "white"; echo $ k % 9 = 1? "":" ";?>
     
     
  
  ":" "; $ K ++;}?>
    Thank you for answering the question. you can try it again, but the page is not specified during the initial opening, so the page will not be displayed. I will change it myself.

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.