What are common pitfalls when calculating page numbers for image galleries in PHP?

One common pitfall when calculating page numbers for image galleries in PHP is not taking into account the total number of images and the desired number of images per page. To solve this, you need to divide the total number of images by the number of images per page and round up to determine the total number of pages needed.

$totalImages = 50;
$imagesPerPage = 10;
$totalPages = ceil($totalImages / $imagesPerPage);
echo "Total Pages: " . $totalPages;