[Original] Sub-page intermediate tutorial Step into page
In the introductory tutorial, when the page number is mentioned, this article is mainly for discussion here. Welcome to shoot Bricks.
The source code is similar to the previous primary paging tutorial, just a little improvement in the output page link
What is stepping paging? Here's a simple word.
When the total number of pages reached hundreds of, if you follow the previous article in the practice, then the page becomes very ugly, all the page numbers are lost, so it is very unsightly, so it is necessary to control the output page numbers. If you are careful, look at Discuz's pagination. The final page number is always not more than a certain number.
PHP Code
<title>Pagination instance</title>
$total _page $total _page: $page;//Avoid $_get["page"] greater than total pages//page link start $page_link= "", if ($total _page>1) {$page _link= "altogether { $total _page} page "; $page _link.= "The current {$page} page"; $page _link.= "Home"; if ($page >1) {//page number is greater than 1, display the previous page link $pre _page= $page-1; $page _link.= "<<"; }//Flip list//step paging, the number of page Flip list always shows only 9 or custom number, this example defines only 9, the current page shows 4 page numbers if ($total _page>9) {if ($page >4) {$from = $page-4; $to = $page +4; if ($to > $total _page) {$from = $total _page-8; $to = $total _page; }} else {$from = 1; $to = 9; }} else {$from = 1; $to = $total _page; } for ($i = $from; $i <= $to; $i + +) {if ($i = = $page) {//Highlight current page number $page _link.= "$i"; } else {$page _link.= "$i"; }}//page is less than the total number of pages to display the next page link $next _page= $page +1; if ($next _page<$total _page) {$page _link.= ">>"; } $page _link.= "last page";} Output record $offset= ($page-1) * $page _size; $query =mysql_query ("SELECT * from Product limit $offset, $page _size") or Die (Mysql_ Error ()); echo "
"While ($rs =mysql_fetch_array ($query)) {echo"
- {$rs ["id"]}-{$rs ["Ename"]}
";} echo "
"Echo" $page _link ";? >
------Solution--------------------
A rare and green article to see.
------Solution--------------------
Good tutorial, for beginners Oh, I have my own pagination class