[Urgent] modify the simple paging algorithm !!!! PHPcode // content pagination $ c_page =$ _ GET ['Page']; // The current page $ contstr = $ NewsCentent; // News content // read from the database $ lis [urgent] modification of the simple paging algorithm !!!!
PHP code
// Content pagination $ c_page =$ _ GET ['Page']; // The current page $ contstr = $ NewsCentent; // News content // The content read from the database $ listbyte = 8000; // The number of bytes per page is displayed, under normal circumstances, you can set it to 5000 or another // # search for the article pagination point ---------- $ contlen = strlen ($ contstr); // News length $ j = 0; // total number of pages $ listat [0] = 0; // array of paging points position $ lookAt = 0; // the start position of the paging point for ($ I = 1; $ I <$ contlen/$ listbyte + 1; $ I ++) {if ($ lookAt <$ listbyte) $ lookAt = $ listbyte; // the start position of the paging point is the default page length. if ($ lookAt> $ contlen) {// if the length of less than one page is $ j ++; $ listat [$ j] = $ contlen; // store the break of the paging position on page $ j;} $ endAt = strpos ($ contstr, "\ n ", $ lookAt); // search for the end position of the last part of the page (the content of the page is within one page) // if the remaining content is less than 1/5 of the page, if ($ endAt> $ contlen-$ listbyte/5 or intval ($ endAt) <1) {$ j ++; $ listat [$ j] = $ contlen; // break;} else {$ j ++; $ listat [$ j] = $ endAt; // store the position of the paging point on page $ j $ lookAt = $ endAt + $ listbyte; // start position of the next paging point search} // print the page number $ pagenum = $ j; // Total page $ page = intval ($ c_page ); if (empty ($ page) or $ page <1 or $ page> $ pagenum) $ page = 1; // $ row [0] indicates the ID, display the content based on the ID after turning the page. // output the content of the current page $ stag = $ page-1; $ startb = $ listat [$ stag]; // start position if ($ startb> 0) // remove the first line break $ startb = $ startb + 1; $ cont = substr ($ contstr, $ startb, $ listat [$ page]-$ startb); // heightlight_string ("$ cont"); // php highlight code output $ ShowContent = $ cont.'
'; If ($ pagenum> 1) {$ ShowPage ='
-
Previous Page
'; For ($ I = 1; $ I <$ pagenum + 1; $ I ++) {if ($ page = $ I) {$ Class = 'class = "onnum" '; $ ShowPage. ='
-
'. $ I .'
';} Else {$ ShowPage. ='
-
'. $ I .'
';}}$ ShowPage. ='
-
Next page
';}
The above is a simple PHP news paging algorithm and news display algorithm. it is an automatic paging algorithm. I want to add a manual paging character to enable paging at any location. please modify it, thank you !!!
------ Solution --------------------
You can write it as a class. Call it wherever it is needed.
------ Solution --------------------
Encapsulated as a class file, which needs to be called