What is wrong with this page? Why are all the five pages displayed?

Source: Internet
Author: User
The shoupage is set to 5. Why are all the pages displayed? I changed the shoupage value and displayed all the pages unchanged. {code ...} the shoupage is set to 5. Why are all the pages displayed? I changed the shoupage value and showed that all the pages have not changed.


  "; Echo"
  
  
    "; Echo'
  • '. $ Page.'/'. $ pagenum.' page |
  • '; If ($ page = 1) {echo'
  • Homepage |
  • '; Echo'
  • Previous Page |
  • ';} Else {echo'
  • Homepage |
  • '; Echo'
  • Previous Page |
  • ';} If ($ pagenum> $ shoupage) {if ($ page> $ pageoffset) {$ start = $ page-$ pageoffset; $ end = $ pagenum> $ page + $ pageoffset? $ Page + $ pageoffset: $ pagenum;} else {$ start = 1; $ end = $ pagenum> $ shoupage? $ Shoupage: $ pagenum;} if ($ page + $ pageoffset> $ pagenum) {$ start = $ start-($ page + $ pageoffset-$ end);} echo'

    '; Echo'

      '; $ Shoupage = 5; $ pageoffset = ($ shoupage-1)/2; $ start = 1; $ end = $ pagenum; for ($ I = $ start; $ I <= $ end; $ I ++) {echo'
    • '. ($ I ).'
    • ';} Echo'
    '; Echo'

    '; If ($ page = $ pagenum) {echo'
  • | Next page |
  • '; Echo'
  • Last page |
  • ';} Else {echo'
  • | Next page |
  • '; Echo'
  • Last page |
  • ';} Echo'
'; Echo'

';};?>

Reply content:

The shoupage is set to 5. Why are all the pages displayed? I changed the shoupage value and showed that all the pages have not changed.


  "; Echo"
  
  
    "; Echo'
  • '. $ Page.'/'. $ pagenum.' page |
  • '; If ($ page = 1) {echo'
  • Homepage |
  • '; Echo'
  • Previous Page |
  • ';} Else {echo'
  • Homepage |
  • '; Echo'
  • Previous Page |
  • ';} If ($ pagenum> $ shoupage) {if ($ page> $ pageoffset) {$ start = $ page-$ pageoffset; $ end = $ pagenum> $ page + $ pageoffset? $ Page + $ pageoffset: $ pagenum;} else {$ start = 1; $ end = $ pagenum> $ shoupage? $ Shoupage: $ pagenum;} if ($ page + $ pageoffset> $ pagenum) {$ start = $ start-($ page + $ pageoffset-$ end);} echo'

    '; Echo'

      '; $ Shoupage = 5; $ pageoffset = ($ shoupage-1)/2; $ start = 1; $ end = $ pagenum; for ($ I = $ start; $ I <= $ end; $ I ++) {echo'
    • '. ($ I ).'
    • ';} Echo'
    '; Echo'

    '; If ($ page = $ pagenum) {echo'
  • | Next page |
  • '; Echo'
  • Last page |
  • ';} Else {echo'
  • | Next page |
  • '; Echo'
  • Last page |
  • ';} Echo'
'; Echo'

';};?>

@ Eapen he has already said the reason.

Here is a demo I wrote. copy and paste it to run it.

If it is digested, you will learn paging. If you still do not know, please feel free to ask me:

$ Np = @ $ _ GET ['page']; // obtain the current page/** set the number of pages to be displayed. * For example, to display 5 pages * for reasonable display, you need to set an offset: You certainly want to get the offset: (5-1)/2 = 2; ---- "5 6 nowpage 8 9 * What if 6 pages are displayed? * This is not the case (6-1)/2! So you actually need to manually calculate it, as long as you make it into 6 pages: 3 + 1 + 2 = 6 so set: $ offset_forward = 3 $ offset_forward = 2 1 indicates the current page ---> 5 6 7 nowpage 9 10 */$ dp = 12; // how many pages are displayed $ offset_forward = 6; // how many records are shown earlier $ offset_after = 5; // how many days are shown later

/--- Paging function ---/
Function display_data ($ np, $ dp, $ offset_forward, $ offset_after ){

$ Length = 1000; // set the number of records if ($ length = 0) {echo 'No data! ';}$ Total_page = ceil ($ length/$ dp); // calculates the total number of pages. /* --- Limit the number of pages: must be greater than 0 and smaller than the total number of pages --- */if (! Isset ($ np) {$ np = 1;} else {if ($ np <1) {$ np = 1;} if ($ np> $ total_page) {$ np = $ total_page; }}$ btn =""; $ Btn. = "Homepage"; $ btn. = "Previous Page"; if ($ total_page <= $ dp) // if the total number of pages is less than the number of pages to be displayed... {$ start_page = 1; $ end_page = $ total_page; for ($ I = $ start_page; $ I <= $ end_page; ++ $ I) {$ btn. = "$ I" ;}} else {// if the total number of pages is greater than the number of points to be displayed... if ($ np <= $ dp) // if the current page is smaller than or equal to the number of pages to be displayed .. {$ start_page = 1; $ end_page = $ dp; for ($ I = $ start_page; $ I <= $ end_page; ++ $ I) {$ btn. = "$ I" ;}} else {// if the current page is greater than the number of pages to be displayed .. if ($ np + $ offset_forward> $ total_page) // if the offset is added to the current page, it will be greater than the total number of pages .... {$ start_page = $ total_page-$ offset_forward-$ offset_after; $ end_page = $ total_page; for ($ I = $ start_page; $ I <= $ end_page; ++ $ I) {$ btn. = "$ I" ;}} else {// if the current page is added, the offset will be less than the total number of pages .... $ start_page = $ np-$ offset_after; $ end_page = $ np + $ offset_forward; for ($ I = $ start_page; $ I <= $ end_page; ++ $ I) {$ btn. = "$ I" ;}}}$ btn. = "next page"; $ btn. = "last page"; echo $ btn;/* --- add a style to the current page -- */echo <
  

EOT;

} Display_data ($ np, $ dp, $ offset_forward, $ offset_after); // executes the paging Logic

?>

Ah, paging writing is complicated...

If you just want to ask why all of them are displayed

The problem lies in 30 31 rows.

$start=1;$end=$pagenum;

Remove these two rows .. Although there are other problems

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.