<?php $query_count = "SELECT * FROM news_events "; $news = News_Events::find_by_sql($query_count); $new = array_shift($news); // 1. the current page number ($current_page) $page = !empty($_GET['page']) ? (int) $_GET['page'] : 1; // 2. records per page ($per_page) $per_page = 1; // 3. total record count ($total_count) if ($new->visible == 1) { $total_count = News_Events::count_all(); } else { $total_count = News_Events::count_all_visible(); } // Find all photos // use pagination instead $pagination = new Pagination($page, $per_page, $total_count); // Instead of finding all records, just find the records // for this page $sql = "SELECT * FROM news_events ORDER BY `id` DESC "; $sql .= "LIMIT {$per_page} "; $sql .= "OFFSET {$pagination->offset()}"; $newsEvents = News_Events::find_by_sql($sql); // Need to add ?page=$page to all links we want to // maintain the current page (or store $page in $session) $counter = 1; ?> <ul> <?php