<?php require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'bootstrap.php'; $bookSelector = new BookSelect(); // find out how many results will be displayed on one page $results = Config::get('pagination/results_per_page'); // find out how many records there are for given context if (Input::exists('get') && Input::found('author')) { $records = $bookSelector->countBooks('author', Input::get('author')); } else { if (Input::exists('get') && Input::found('genre')) { $records = $bookSelector->countBooks('genre', Input::get('genre')); } else { if (Input::exists('get') && Input::found('title')) { $records = $bookSelector->countBooks('title', Input::get('title')); } else { $records = $bookSelector->countBooks(); } } } // calculate the last page of results $last = ceil($records / $results); // make sure $last cannot be less than 1 $last = $last >= 1 ? $last : 1; // define the number of current page $page = Input::exists('get') && Input::found('page') ? Input::get('page') : 1; // change initial $page value if it's bigger than that of the $last page or less than 1 if ($page < 1) { $page = 1; } else { if ($page > $last) {