Home  >  Article  >  Backend Development  >  Simple implementation tutorial of php paging code

Simple implementation tutorial of php paging code

Guanhui
GuanhuiOriginal
2020-05-05 14:32:135356browse

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;

Output result: 9

4. Finally, render the page turning link based on the total number of pages.

// 翻页链接  
for ($i = 0; $i < $page; $i ++) {  
    echo "" . ($i + 1) . "";  
}

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn