Home > Article > Backend Development > Simple implementation tutorial of php paging code
Simple implementation of php paging code
1. First get the total number of data;
2. Then use Divide the total number of items by the number of items on each page to get the total number of pages;
//模拟总条数 $total = 84; //每页的数量 $count = 10; //计算页数 $page = $total / $count; echo $page;
Output result: 8.4
3. Then use the "ceil()" function to calculate the total number of pages. Convert to an integer, the "ceil()" function means to round up the decimal;
<?php //模拟总条数 $total = 84; //每页的数量 $count = 10; //计算页数 $page = $total / $count; //向上取整 $page = ceil($page); echo $page;
Output result: 9
4. Finally, render the page turning link based on the total number of pages.
// 翻页链接 for ($i = 0; $i < $page; $i ++) { echo "<a href=index.php?page=" . ($i + 1) . ">" . ($i + 1) . "</a>"; }
The above is the detailed content of Simple implementation tutorial of php paging code. For more information, please follow other related articles on the PHP Chinese website!