Php code for pagination comment:
0) {// of course, only data in the table will be displayed with the following program $ pageSize = 2; // number of records displayed on each page # Current page number $ page, this value is obtained from the link of the page. if this parameter is not provided, the first page if (! Empty ($ _ GET ['Page']) {$ page = $ _ GET ['Page'];} else {$ page = 1 ;}$ totalPage = (int) ceil ($ totalRows/$ pageSize ); // The total number of pages equals to the total number of records divided by the number of entries displayed on each page. the fractional part is taken into an integer. # The following is only a judgment on the validity of some data. if (int) $ page <1) {$ page = 1;} if (int) $ page> $ totalPage) {$ page = $ totalPage ;} # the following addition and subtraction 2 shows the first two pages and the last two pages of the current page. the Number 2 can be modified as needed, the purpose is to display only a certain number of paging links like google, so as not to display dozens or even hundreds of paging links when there is a large amount of data. # of course, if you must display all of them, you only need to specify $ begin = 1; $ end = $ totalPage; $ begin = $ page-4; $ end = $ page + 5; # Here are some data validity judgments: if ($ page <5) {$ begin = 1; $ end = 10; // Here is the number of available links you want to provide, in this example, there are 5 pages in front and back of the current page, and the if condition is half of the number of available links} if ($ page> $ totalPage-5) {$ begin = $ totalPage-9; $ end = $ totalPage;} if ($ begin <1) {$ begin = 1;} if ($ end> $ totalPage) {$ end = $ totalPage ;} # Start to output the paging link/* =========================display the first paging link start ========== ========= */echo"
"; Echo"
| $ TotalRows |
$ Page/$ totalPage | "; If ($ page> 1) {echo"
| < |
< | ";}For ($ I =$ begin; $ I <=$ end; $ I ++) {if ($ I ==$ page) {echo ("
");} Else {echo (" |
");} Echo (" $ I "); echo (" | ");} If ($ page <$ end) {echo"
> |
> | | ";} Echo"
| "; Echo"
"; /* ========================== Show the end of the first paging link ==================== = * // * = ==== */echo "total $ totalPage page $ totalRows <Back "; # The next step is to display the 1, 2, 3, and 4 with links... for ($ I = $ begin; $ I <= $ end; $ I ++) {echo (""); echo (""); if ($ I = $ page) echo (""); echo ("$ I"); if ($ I = $ page) echo (""); if ($ I! = $ End) echo ("|");} echo ("Next> \ n"); $ selecet_page ="\ N "; for ($ I = 1; $ I <= $ totalPage; $ I ++) {if ($ I ==$ page) {$ selecet_page. ="$ I\ N ";}else {$ selecet_page. ="$ I\ N ";}}$ selecet_page. ="\ N "; echo $ selecet_page; /* =============================show The second type of paging link end ====================== = */# After the link is displayed, the data is displayed, of course, you can make full use of the display effect. here we only provide a general mode # By the way: no matter what effect page the artist sets for you, make full use of our if for statement to get $ beginNum = ($ page-1) * $ pageSize; // The number of query records starting FROM $ SQL _select = "SELECT * FROM $ dbtablename LIMIT $ beginNum, $ pageSize"; $ rs = mysql_query ($ SQL _select, $ conn ); $ rs_field_counts = mysql_num_fields ($ rs); // The number of queried fields echo ("
\ N "); echo ("
\ N "); # display the header. of course, it is unlikely that the field name of the database will be directly output in actual applications, then write the following for loop directly as the header you want to display ($ I = 0; $ I <$ rs_field_counts; $ I ++) {$ rs_field_name = mysql_field_name ($ rs, $ I); echo ("
| $ Rs_field_name | ");} Echo (" \ n
\ N "); # Display Data $ row_number = 0; // This variable is used to control the row display color, while ($ row = mysql_fetch_array ($ rs )) {# determine whether there are singular or even rows. this principle is also applicable when two records are displayed on each line (image-based product display is generally used) if ($ row_number % 2 = 0) {$ tr_color = "# CCFFFF";} else {$ tr_color = "# CCFFCC";} echo ("
\ N "); for ($ I = 0; $ I <$ rs_field_counts; $ I ++) {echo ("
| "); If (empty ($ row [$ I]) {echo (" ");} else {echo ($ row [$ I]);} echo (" | ");} Echo (" \ n
\ N "); $ row_number ++;} echo"
\ N "; // do not forget to output this output when the data display ends! Only here is your success .} Else {// if the table does not have data echo ("sorry, no matching data!
\ N ") ;}// the following two pure-cooked samples: mysql_free_result ($ rs); mysql_close ($ conn);?>
Php code
0) {// of course, only data in the table will be displayed with the following program $ pageSize = 2; // number of records displayed on each page # Current page number $ page, this value is obtained from the link of the page. if this parameter is not provided, the first page if (! Empty ($ _ GET ['Page']) {$ page = $ _ GET ['Page'];} else {$ page = 1 ;}$ totalPage = (int) ceil ($ totalRows/$ pageSize ); // The total number of pages equals to the total number of records divided by the number of entries displayed on each page. the fractional part is taken into an integer. # The following is only a judgment on the validity of some data. if (int) $ page <1) {$ page = 1;} if (int) $ page> $ totalPage) {$ page = $ totalPage ;} # the following addition and subtraction 2 shows the first two pages and the last two pages of the current page. the Number 2 can be modified as needed, the purpose is to display only a certain number of paging links like google, so as not to display dozens or even hundreds of paging links when there is a large amount of data. # of course, if you must display all of them, you only need to specify $ begin = 1; $ end = $ totalPage; $ begin = $ page-4; $ end = $ page + 5; # Here are some data validity judgments: if ($ page <5) {$ begin = 1; $ end = 10; // Here is the number of available links you want to provide, in this example, there are 5 pages in front and back of the current page, and the if condition is half of the number of available links} if ($ page> $ totalPage-5) {$ begin = $ totalPage-9; $ end = $ totalPage;} if ($ begin <1) {$ begin = 1;} if ($ end> $ totalPage) {$ end = $ totalPage ;} # Start to output the paging link/* =========================display the first paging link start ========== ========= */echo"
"; Echo"
| $ TotalRows |
$ Page/$ totalPage | "; If ($ page> 1) {echo"
| < |
< | ";}For ($ I =$ begin; $ I <=$ end; $ I ++) {if ($ I ==$ page) {echo ("
");} Else {echo (" |
");} Echo (" $ I "); echo (" | ");} If ($ page <$ end) {echo"
> |
> | | ";} Echo"
| "; Echo"
"; /* ========================== Show the end of the first paging link ==================== = * // * = ==== */echo "total $ totalPage page $ totalRows <Back "; # The next step is to display the 1, 2, 3, and 4 with links... for ($ I = $ begin; $ I <= $ end; $ I ++) {echo (""); echo (""); if ($ I = $ page) echo (""); echo ("$ I"); if ($ I = $ page) echo (""); if ($ I! = $ End) echo ("|");} echo ("Next> \ n"); $ selecet_page ="\ N "; for ($ I = 1; $ I <= $ totalPage; $ I ++) {if ($ I ==$ page) {$ selecet_page. ="$ I\ N ";}else {$ selecet_page. ="$ I\ N ";}}$ selecet_page. ="\ N "; echo $ selecet_page; /* =============================show The second type of paging link end ====================== = */# After the link is displayed, the data is displayed, of course, you can make full use of the display effect. here we only provide a general mode # By the way: no matter what effect page the artist sets for you, make full use of our if for statement to get $ beginNum = ($ page-1) * $ pageSize; // The number of query records starting FROM $ SQL _select = "SELECT * FROM $ dbtablename LIMIT $ beginNum, $ pageSize"; $ rs = mysql_query ($ SQL _select, $ conn ); $ rs_field_counts = mysql_num_fields ($ rs); // The number of queried fields echo ("
\ N "); echo ("
\ N "); # display the header. of course, it is unlikely that the field name of the database will be directly output in actual applications, then write the following for loop directly as the header you want to display ($ I = 0; $ I <$ rs_field_counts; $ I ++) {$ rs_field_name = mysql_field_name ($ rs, $ I); echo ("
| $ Rs_field_name | ");} Echo (" \ n
\ N "); # Display Data $ row_number = 0; // This variable is used to control the row display color, while ($ row = mysql_fetch_array ($ rs )) {# determine whether there are singular or even rows. this principle is also applicable when two records are displayed on each line (image-based product display is generally used) if ($ row_number % 2 = 0) {$ tr_color = "# CCFFFF";} else {$ tr_color = "# CCFFCC";} echo ("
\ N "); for ($ I = 0; $ I <$ rs_field_counts; $ I ++) {echo ("
| "); If (empty ($ row [$ I]) {echo (" ");} else {echo ($ row [$ I]);} echo (" | ");} Echo (" \ n
\ N "); $ row_number ++;} echo"
\ N "; // do not forget to output this output when the data display ends! Only here is your success .} Else {// if the table does not have data echo ("sorry, no matching data!
\ N ") ;}// the following two pure-cooked samples: mysql_free_result ($ rs); mysql_close ($ conn);?>