PHP code example of rogerthomas84 / ohpage
1. Go to this page and download the library: Download rogerthomas84/ohpage library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rogerthomas84 / ohpage example snippets
$db = new \MongoClient('mongodb://my.database.host:27017'); // Set up your database connection
$collection = $db->selectCollection('mydb', 'mycollection');
$perPage = 10; // How many results per page?
$currentPage = 1; // The current page
$totalResults = $collection->count(); // Get the total from the DB
$instance = new PaginateHelper($perPage, $currentPage, $totalResults);
$results = $collection->find()->sort(
array('createdDate' => -1)
)->skip(
$instance->getQueryOffset()
)->limit(
$instance->getQueryLimit()
);