Are there any recommended PHP libraries or frameworks that simplify the process of pagination for database results?

When dealing with database results that need to be paginated, it can be cumbersome to manually handle the logic of fetching the correct subset of results and displaying pagination links. Using a PHP library or framework specifically designed for pagination can simplify this process by providing easy-to-use functions for generating pagination links and handling the retrieval of the correct subset of results. One recommended PHP library for pagination is "Pagerfanta". It provides a simple and flexible way to paginate database results in PHP applications. By using Pagerfanta, you can easily generate pagination links and retrieve the correct subset of results based on the current page.

// Include the Pagerfanta autoloader
require 'vendor/autoload.php';

use Pagerfanta\Adapter\DoctrineDbalAdapter;
use Pagerfanta\Pagerfanta;

// Assume $db is your Doctrine\DBAL\Connection object
$adapter = new DoctrineDbalAdapter($db, $queryBuilder);

$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage(10); // Number of items per page
$pagerfanta->setCurrentPage($currentPage); // Current page number

// Get the current page of results
$results = $pagerfanta->getCurrentPageResults();

// Display the results
foreach ($results as $result) {
    // Display each result
}

// Display pagination links
echo $pagerfanta->render();