Younger brother, my paging, but there is an exception. Please check it out.

Source: Internet
Author: User
My pages, but there is an error. Please check if this is my page. But there is an error. for example, if I click the last page and then the previous page, she is still on this page. this is also the case after I click the next page on the homepage. ask for advice! $ SQL = & quot; select * frompl_transaction_sun & quot; $ query = mysql_quer
This is the page I wrote. But there is an error. for example, if I click the last page and then the previous page, she is still on this page. this is also the case after I click the next page on the homepage. ask for advice!

$ SQL = "select * from pl_transaction_sun ";
$ Query = mysql_query ($ SQL );
$ Num = mysql_num_rows ($ query );

$ Pagesize = 3;
$ Start = $ _ GET ['start'];
$ Flag = $ _ GET ['flag'];

// Determine whether $ start has a value
If ($ start = null ){
$ Start = 0;
}

// Determine whether $ flag has a value
If ($ flag = null ){
$ Flag = 0;
}

$ Sql1 = "select * from pl_transaction_sun limit $ start, $ pagesize ";
$ Query1 = mysql_query ($ sql1 );
// $ Num1 = mysql_num_rows ($ query1 );

// Determine the flag bit to determine the value of $ start
If ($ flag = 1 and $ start + $ pagesize <$ num ){
$ Start = $ start + $ pagesize;
}
If ($ flag = 2 and $ start + $ pagesize> 0 ){
$ Start = $ start-$ pagesize;
}

// Start id on the last page
If ($ num % $ pagesize )! = 0 ){
$ Lastpage = $ num-($ num % $ pagesize );
} Else {
$ Lastpage = $ num-$ pagesize;
}

// Determine the page number and current page code
$ Pagenum = ceil ($ num/$ pagesize );

If ($ start = 0 ){
$ Nowpage = 1;
} Else {
$ Nowpage = ($ start/$ pagesize) + 1;
}
Print (" ");
// Display the judgment part by page
If ($ start = 0 and $ pagesize <$ num ){
Print ("[Homepage] [previous page]
[Next Page]
[Last Page ]");
} Elseif ($ start >=$ num-$ pagesize and $ pagesize <$ num ){
Print ("
[Homepage]
[Previous page]
[Next Page] [last page ]");
} Elseif ($ pagesize >=$ num ){
Print ("[Homepage] [Previous Page] [Next Page] [last page ]");
} Else {
Print ("
[Homepage]
[Previous page]
[Next Page]
[Last Page ]");
}


------ Solution --------------------
$ Query1 = mysql_query ($ sql1 );
It should be executed after the new $ start is generated

The control logic is too complex. you only need to pass the desired page number. It is recommended to adjust it.

------ Solution --------------------
For a beginner, Shenma is a cloud ......
------ Solution --------------------
Paging is actually very simple. determine how many entries are displayed on a page and then calculate the number of all entries.
------ Solution --------------------
Pagination is a small gap that must be crossed by web programs. It is worthwhile to spend some time.

Because there are too many places to use, you need to encapsulate it into a function or a method in the class.
PHP code
$ Page = isset ($ _ GET ['Page'])? Intval ($ _ GET ['Page']): 1; $ perNum = 10; $ offset = max ($ page-1) * $ perNum), 0 ); // SQL $ vpage = page ($ total, $ page, $ perNum, $ url );

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.