// Pagination:
$resultsPerPage = 14;
// Pagination
$page = ( ! empty($_GET['Page']) ? $_GET['Page'] : ( ! empty($_POST['Page']) ? $_POST['Page'] : 1 ) );
// Count ALL the MOT records:
$resultsMOT = $DB->query("
SELECT
COUNT(mot_id)
FROM
mots
");
$numOfResults = $resultsMOT->fetch();
$numberOfPages = ceil( ( $numOfResults['COUNT(mot_id)'] / $resultsPerPage ) );
// PAGE Range test:
if( filter_var( $page, FILTER_VALIDATE_INT, [ "options" => [ 'min_range' => 1, 'max_range' => $numberOfPages ] ] ) === false ) { $page = 1; }
$start = ( ( $page - 1 ) * $resultsPerPage );
echo 'Start: ', $start . ' Number of pages required (unrounded): ', ( $numOfResults['COUNT(mot_id)'] / $resultsPerPage ), ' Rounded:', $numberOfPages;
pagination_Build( ['current' => $page, 'max' => $numberOfPages, 'link' => "?module=MOT&action=Search"] );
$fetchMots = $DB->query("
SELECT
m.*, v.*, c.client_name
FROM
mots as m
INNER JOIN
vehicles as v
ON
( v.vehicle_mot = m.mot_id )
INNER JOIN
clients as c
ON
( c.client_id = m.mot_client )
ORDER BY
m.mot_expiry
LIMIT
$start, $resultsPerPage
");
For some reason, some results are repeated across two pages - the strange thing is it doesn't seem to effect EVERY page span...