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);