setTotal(50); // 50 products to be paginated $pagination->perPage = 10; // 10 products per page echo $pagination->createLinks(); ?>
prepare('SELECT * FROM mytable'); $pagination = new Pagination(); $pagination->setTotal($stmt->rowCount()); // Total number of query results $pagination->perPage = 20; // 20 results per page echo $pagination->createLinks(); ?>In this example, we use a database query to retrieve data and set the total number of results to be paginated. The createLinks() method will generate pagination links for the query results. Package library: The Pagination class may be part of a database library or framework that includes pagination functionality.