Home >Backend Development >PHP Tutorial >PHP long article paging principle and implementation procedure_PHP tutorial
Below I will analyze the long article paging and article paging program codes. Friends in need can refer to it.
Method 1: Paging according to word count control
Paging by word count is simple and easy to use, but the effect is not good.
General idea: First, set the maximum number of words that can be accommodated on each page; then, calculate the total number of words in the article content, and then calculate the total number of pages based on the total number of words and the maximum number of words on a single page. In this way, the entire preparation for paging has been completed.
The specific display content of each page can be achieved through content interception. For example: if the page contains 500 words and the article contains 2200 words, then when page=2 is passed to the page, the content between 501st and 1000th should be displayed.
This method is simple, but you may encounter trouble when displaying. Article content is usually accompanied by HTML tags. It is difficult to close the HTML tags when cutting content. If this work is not done well, the effect after paging will be It's obviously not good either.
The code is as follows | Copy code |
$current=$_REQUEST['page_t']; function ff_page($content,$page) echo "".$page."/".$PageCount."page "; If($page>1) echo "Previous page "; else else echo "Previous page"; for( $i=1 ; $i <= $PageCount ; $i++) { echo "[".$i."] "; } if($page < $PageCount) echo " Next page "; else echo "next page"; echo " } } } ?>
|
The code is as follows | Copy code |
class contentpage function __construct($content = "",$pagesize = 10,$breakflag ="n",$pageurl = '',$pagevar = 'p') //Total number of pages, starting position and ending position of each page //Content of each page } //Pagination bar //输出数字页码 $content = "第一页:文章内容分页阿斯顿浪费空间阿斯顿来看福建省地方吉林省福建路口附近大手拉飞机上浪费的说浪费监理费 |
更多详细内容请查看:http://www.bKjia.c0m/phper/php-gj/35233.htm