Home > Backend Development > PHP Problem > Simple implementation tutorial of php paging code

Simple implementation tutorial of php paging code

Guanhui
Release: 2023-02-28 21:58:01
Original
5604 people have browsed it

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;
Copy after login

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;
Copy after login

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>";  
}
Copy after login

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!

Related labels:
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template