PHP - Get Number of Pages
Solution 1
Try ceil() function.
$pages = ceil($items/$itemsPerPage);
Solution 2
I believe the ceiling function is what you're looking for.
ceil($items/$items_per_page)
Solution 3
$count_pages = ceil($total / $items_per_page);
Solution 4
This should do the trick for you. Ceil rounds numbers upwards, always up.
<?php
$maxNrOfPages = ceil($max/$itemsPerPage);
?>
![Daniel Harris](https://i.stack.imgur.com/u4g5T.jpg?s=256&g=1)
Daniel Harris
I'm currently a full stack developer with over 7 years of solid experience in full-stack web development. I have a good foundation in front-end and back-end development using the LAMP stack including relational databases, client-side and server-side scripting, and mobile-first development. My specialties consist of system administration to the development, optimization, and deployment of professional websites. I also convert designs into SEO-optimized and mobile-friendly websites. Since 2009, I've worked on many PHP/MySQL projects which included an event calendar system, custom content management systems, e-commerce shopping carts, customer data systems, order management systems, custom database management systems, and product/service management systems. I've also developed on over 20 websites. I develop websites for businesses, non-profits, and individuals. I have skills to make websites show on the first page of Google. For example, my website SpaceCoastSites.com has achieved 2,645 relevant long-tail keywords that ranked #1 on Google. I’m also skilled in using social media platforms to advertise and bring interest to businesses. Additionally, I can convert web designs from Photoshop into perfect fully-coded front-end pages. I'm also experienced in software documentation and can easily adapt to new software development environments and languages when needed.
Updated on June 04, 2022Comments
-
Daniel Harris about 2 years
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