Little brother my page, but there are anomalies, help to see

Source: Internet
Author: User
My page, but there are mistakes, help to see
This is the pagination I wrote. But there are errors, such as I click on the last page, she still on this page, I ordered the homepage and then the next page after the situation, 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 if the $start has a value
if ($start = = null) {
$start = 0;
}

Determine if the $flag has a value
if ($flag = = null) {
$flag = 0;
}

$sql 1 = "SELECT * from Pl_transaction_sun limit $start, $pagesize";
$query 1 = mysql_query ($sql 1);
$num 1 = mysql_num_rows ($query 1);

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

Last page Start logo
if ($num% $pagesize)! = 0) {
$lastpage = $num-($num% $pagesize);
}else{
$lastpage = $num-$pagesize;
}

Determine the number of pages and the current page code
$pagenum = Ceil ($num/$pagesize);

if ($start = = 0) {
$nowpage = 1;
}else{
$nowpage = ($start/$pagesize) + 1;
}
Print (" ");
Pagination Displays the judging section
if ($start = = 0 and $pagesize < $num) {
Print (" "Home" "prev"
"Next Page"
"Last"");
}elseif ($start >= $num-$pagesize and $pagesize < $num) {
Print ("
Home
"on page"
"Next page" "End"");
}elseif ($pagesize >= $num) {
Print (" "Home" "prev" "Next" "Last"");
}else{
Print ("
Home
"on page"
"Next Page"
"Last"");
}


------Solution--------------------
$query 1 = mysql_query ($sql 1);
Should be executed after the new $start has been created

The control logic is too complex to pass a page number that is expected to be displayed. Recommended adjustment

------Solution--------------------
For a beginner, God horse is a floating cloud ...
------Solution--------------------
Paging is actually very simple, set a page to show how many bars, and then calculate all the number of bars
------Solution--------------------
Paging is a small ditch that a Web program must span. It is worthwhile to spend some time.

Because there are too many places to use, you need to encapsulate a method in a function or class
PHP Code
$page = isset ($_get[' page ')?  Intval ($_get[' page '): 1; $perNum = ten; $offset = Max ((($page-1) $perNum), 0);//For 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.