How to write php paging code
This article introduces the knowledge of "how to write php paging code". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
There are many ways to page PHP, and today we will demonstrate this feature with a small example.
The copy code is as follows:
$result = ""
/ / previous page
If ($offset > 0) {
$result. = "
Prev
"
}
$pages = $allPageNums; / / Total number of pages
$page = $curPage; / / current number of pages
$page_len = 9
$page_len = ($page_len%2)? $number of page_len:$pagelen+1;// pages
$pageoffset = ($page_len-1) / 2 the left and right offset of the number of pages / number of pages
If ($pages > $page_len) {
/ / if the current page is less than or equal to the left offset
If ($page=$pages+1) {
$init = $pages-$page_len+1
$max_p = $pages
} else {
/ / calculation when both left and right offsets exist
$init = $page-$pageoffset
$max_p = $page+$pageoffset
}
}
} else {
$init = 1
$max_p = $pages
}
For ($I ($offset+$maxrow)) {
$result. = "
Next
"
}
This is the end of "how to write php paging code". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!