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 correct. if any problem occurs, please read the code. thank you very much! The code is as follows: & lt ;? Php & nbsp; $ page & nbsp; $ _ GET [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 = $ _ 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 $ 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 ('127. 0.0.1: 100', '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;?>------ Solution ----------------------What is your query string $ 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------ Solution ----------------------
$ Page = $ _ GET ["page"];Function Page ($ rows, $ page_size ){Global $ page, $ select_from, $ select_limit, $ pagenav;$ Page_count = ceil ($ rows/$ page_size );If ($ page <= 1------ Solution ----------------------$ 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 $ 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 ('127. 0.0.1: 100', '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 );
?>
$ 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; ?>
------ Solution ----------------------
$ 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 );
You haven't used the above three lines. comment them out.
$ Modify the SQL statement. the SQL statement corresponding to $ r is used in the following loop.
So it's always the same