PHP paging (imitating google)-answers to interview questions. The answer to the written test is not very good, especially for the JS part, which is why I haven't reviewed it for a long time. The question on the machine is to write a class similar to google paging. when we want to take the maximum integer similar to 92, how can we not answer well in the written test, especially in the JS section, it is also the reason why I haven't reviewed it for a long time.
On the machine, the question is to write a class similar to google paging. when we want to take the maximum integer similar to 9/2, we can't remember the name of the function ceil, and we have been dizzy for a long time.
Finally, the test program is not wrong, but it cannot be displayed normally. later (after going home), I checked the statement: for ($ I = 0; $ I ++; $ I <9) was wrong, so I decided to write it again, so I had the following code:
The code is as follows:
/*
The display style is as follows:
[1] 2 3 4 5 6 7 8 9 10... 100 Last Page
Home Page 1... 12 13 14 15 [16] 17 18 19 20... 100 at the end of the next page
Home Page 1 .. 92 93 94 95 96 97 98 [99] 100
Usage:
$ CurrentPage = $ _ GET ['Page']? $ _ GET ['Page']: 1;
$ Pagep = new pagep (500, 10, 11, $ currentPage, 'Test. php? Page = ');
$ Pagep-> show ();
*/
Class pagep
{
Public $ part1;
Public $ part2;
Public $ part3;
Public $ part4;
Public $ part5;
/*
Split the following page display:
Home Page 1... 12 13 14 15 [16] 17 18 19 20... 100 at the end of the next page
$ Part1: Homepage
$ Part2: 1 ..
$ Part3: 12 13 14 15 [16] 17 18 19 20
$ Part4: .. 100
$ Part5: Next page
*/
Public $ allPage; // The total number of pages.
Public $ allRocords; // The total number of records.
Public $ perPage; // number of records per page
Public $ showPagesNo; // displays the total number of page numbers in the pagination bar. There are a total of 11 display styles.
Public $ currentPage; // current page
Public $ urlModel; // Url link style
Public $ startHidden; // when the page number of 1... appears, the middle page is hidden.
Public $ endHidden; // hide the middle page at the end of the page when... 100 is displayed
Public function _ construct ($ allRocords, $ perPage, $ showPagesNo, $ currentPage, $ urlModel ){
$ This-> allRocords = $ allRocords;
$ This-> perPage = $ perPage;
$ This-> showPagesNo = $ showPagesNo;
$ This-> currentPage = $ currentPage;
$ This-> urlModel = $ urlModel;
$ This-> allPage = $ this-> getAllPage ();
$ This-> startHidden = $ this-> getInt ($ this-> showPagesNo)/2); // 6
$ This-> endHidden = $ this-> allPage-$ this-> startHidden; // 94
}
Public function getUrl ($ _ index = ''){
$ _ Current = $ _ index;
If ($ _ index = 'pre') $ _ current = $ this-> currentPage-1;
If ($ _ index = 'next') $ _ current = $ this-> currentPage + 1;
If ($ _ index = '') $ _ current = $ this-> allPage;
Return $ this-> urlModel. $ _ current;
}
Public function getAllPage (){
Return $ this-> getInt ($ this-> allRocords/$ this-> perPage );
}
Public function getInt ($ _ float ){
$ _ Int = $ _ float;
If ($ _ index = strpos ($ _ float, '.') = true ){
$ _ Int = substr ($ _ float, 0, $ _ index );
$ _ Int ++;
}
// No alternative plan for ceil
Return $ _ int;
}
Public function getPart1 (){
$ Content = 'geturl (1). '"> homepage getUrl ('Pre').'"> previous page ';
If ($ this-> currentPage <= $ this-> startHidden ){
$ Content = '';
}
Return $ content;
}
Public function getPart2 (){
$ Content = 'geturl (1). '"> 1 ';
$ Add = '';
If ($ this-> currentPage> $ this-> startHidden ){
$ Add = '...';
}
If ($ this-> currentPage = 1 ){
$ Content = '[1]';
$ Add = '';
}
$ Part2 = $ content. $ add;
Return $ part2;
}
Public function getPart3 (){
$ Content = '';
If ($ this-> currentPage <= $ this-> startHidden ){
// [1] 2 3 4 5 6 7 8 9 10... 100 Last Page
$ Long = $ this-> showPagesNo-2;
For ($ I = 0; $ I <$ long; $ I ++ ){
$ J = $ I + 2;
If ($ j = $ this-> currentPage ){
$ Content. = '['. $ this-> currentPage. ']';
} Else {
$ Content. = 'geturl ($ j). '">'. $ j .'';
}
}
} Elseif ($ this-> currentPage >=$ this-> endHidden ){
// On the homepage, 1 .. 92 93 94 95 96 97 98 [99] 100
$ Long = $ this-> showPagesNo-2;
$ _ Start = $ this-> allPage-$ long;
For ($ I = 0; $ I <$ long; $ I ++ ){
$ J = $ _ start + $ I;
If ($ j = $ this-> currentPage ){
$ Content. = '['. $ this-> currentPage. ']';
} Else {
$ Content. = 'geturl ($ j). '">'. $ j .'';
}
}
} Else {
// The last page of the home page 1... 12 13 14 15 [16] 17 18 19 20... 100
$ Long = $ this-> showPagesNo-2;
$ Offset = $ this-> getInt ($ long/2)-1;
$ _ Start = $ this-> currentPage-$ offset;
For ($ I = 0; $ I <$ long; $ I ++ ){
$ J = $ _ start + $ I;
If ($ j = $ this-> currentPage ){
$ Content. = '['. $ this-> currentPage. ']';
} Else {
$ Content. = 'geturl ($ j). '">'. $ j .'';
}
}
}
$ Part3 = $ content;
Return $ part3;
}
Public function getPart4 (){
$ Content = 'geturl (). '">'. $ this-> allPage .'';
$ Add = '';
If ($ this-> currentPage <$ this-> endHidden ){
$ Add = '...';
}
If ($ this-> currentPage ==$ this-> allPage ){
$ Content = '['. $ this-> allPage. ']';
$ Add = '';
}
$ Part4 = $ add. $ content;
Return $ part4;
}
Public function getPart5 (){
$ Content = 'geturl ('next'). '"> getUrl ().'"> last page ';
If ($ this-> currentPage >=$ this-> endHidden ){
$ Content = '';
}
Return $ content;
}
Public function show (){
// Illegal judgment
If (! Is_numeric ($ this-> currentPage) | $ this-> currentPage <0 | $ this-> currentPage> $ this-> allPage ){
Print 'Error: pageNo is flase ';
Return;
}
// If the total number of pages does not reach the total number of pages displayed on the page bar, all are displayed.
If ($ this-> allPage <$ this-> showPagesNo ){
$ Long = $ this-> allPage;
For ($ I = 0; $ I <$ long; $ I ++ ){
$ J = $ I + 1;
If ($ j = $ this-> currentPage ){
$ Content. = '['. $ this-> currentPage. ']';
} Else {
$ Content. = 'geturl ($ j). '">'. $ j .'';
}
}
Print $ content;
Return;
}
$ This-> part1 = $ this-> getPart1 ();
$ This-> part2 = $ this-> getPart2 ();
$ This-> part3 = $ this-> getPart3 ();
$ This-> part4 = $ this-> getPart4 ();
$ This-> part5 = $ this-> getPart5 ();
Print $ this-> part1. $ this-> part2. $ this-> part3. $ this-> part4. $ this-> part5;
}
}
?>
Bytes. On the machine, the question is to write a class that imitates google pages. when we want to take the maximum integer similar to 9/2, how can we get it...