= $totalTwts ) { //echo "Only " . $totalTwts . " so no need for pagnation. (max: ". $twts_per_page . ")
"; $paginateTwts = false; } else { //echo "Over " . $twts_per_page . " so pagnation is needed.
"; $paginateTwts = true; } $page = 1; if (!empty($_GET['page'])) { $page = intval($_GET['page']); } // If we should paginate our twts list if (!empty($paginateTwts)) { $startingTwt = (($page - 1) * TWTS_PER_PAGE); $twts = array_slice($twts, $startingTwt, TWTS_PER_PAGE); } # Approach 2: Ignore invalid page numbers, and adjust the number between 1 and the last page $currentPage = max(1, min($_GET["page"], $totalPages)); # And then in the HTML template only show the next page link if we are NOT on the last one if ($currentPage < $totalPages) { $output .= '> Next Page'; } $totalTwts = count($twts); //echo "pagnation twts: " . $totalTwts; $totalPages = ceil($totalTwts / $twts_per_page); //echo "
total pages: " . $totalPages; $page_url = $_SERVER['REQUEST_URI']; //echo $page_url."
"; if (!empty($_GET['page'])) { if (preg_match('/\?page=/', $page_url)) { //echo "cotains ?page= so reuse that
"; $page_url = preg_replace('/\?page=\d*/', "", $page_url) . '?page='; } if (preg_match('/&page=/', $page_url)) { //echo "cotains &page= so reuse that
"; $page_url = preg_replace('/&page=\d*/', "", $page_url) . '&page='; } } else { if (!preg_match('/(\?|&)/', $page_url)) { //echo "No param, so use ?page
"; $page_url = $page_url . '?page='; } if (!preg_match('/(\?|&)page/', $page_url)) { //echo "other param than _page, so use &page
"; $page_url = $page_url . '&page='; } } ?>