// set up pagination for a MySQL query $page = isset($_GET['page']) ? $_GET['page'] : 1; $results_per_page = 10; $start_from = ($page - 1) * $results_per_page; $query = "SELECT * FROM products LIMIT $start_from, $results_per_page"; $result = mysqli_query($conn, $query); // use setPaging to show page links $num_rows = mysqli_num_rows($result); $pagination = new Pagination(); $pagination->setPaging($num_rows, $page, $results_per_page); echo $pagination->pageLinks();
// dynamically generate page links based on setPaging input $page = isset($_GET['page']) ? $_GET['page'] : 1; $items_per_page = 5; $total_items = 50; $pagination = new Pagination(); $pagination->setPaging($total_items, $page, $items_per_page); echo $pagination->pageLinks();In this example, we're using setPaging to generate page links based on the total number of items we want to display, the number of items per page, and the current page number. This can be useful for dynamically generated content or search results pages. The setPaging method is typically part of a larger pagination library or package in PHP. Some popular examples of pagination libraries for PHP include: - Pager (https://github.com/josephspurrier/pager) - Laravel Pagination (https://laravel.com/docs/8.x/pagination) - KnpPaginatorBundle (https://github.com/KnpLabs/KnpPaginatorBundle)