PHP - 获取页数[关闭]

How do I get the number of pages if I know the total number of items there are and how many items are shown on each page? For example, I know that I have 11 items and each page shows 10 items. So I would have 2 pages. How would I get the number of pages in PHP?

Thanks

Try ceil() function.

$pages = ceil($items/$itemsPerPage);

$count_pages = ceil($total / $items_per_page);

This should do the trick for you. Ceil rounds numbers upwards, always up.

<?php
$maxNrOfPages = ceil($max/$itemsPerPage);
?>

I believe the ceiling function is what you're looking for.

ceil($items/$items_per_page)