session_start(); global $title; require_once 'db.php'; $title = msg('Search Results'); if (empty($_GET['page'])) { $_GET['page'] = 0; } if (empty($_GET['name'])) { $_GET['name'] = ''; } if (empty($_GET['city'])) { $_GET['city'] = ''; } if (empty($_REQUEST['name']) && empty($_REQUEST['city'])) { list($count, $results) = all_people(); } else { list($count, $results) = search_person($_REQUEST); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <?php include 'header.php'; ?> <?php include_once "sidebar.php"; ?> <div id="content">
// Establish the $pagenum variable if (isset($_GET['pn'])) { // Get pagenum from URL vars if it is present, else it is = 1 $pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']); } if ($pagenum < 1) { // This makes sure the page number isn't below 1, or more than our $last page $pagenum = 1; } else { if ($pagenum > $last) { $pagenum = $last; } } $limit = 'LIMIT ' . ($pagenum - 1) * $page_rows . ',' . $page_rows; // This sets the range of rows to query for the chosen $pagenum $people =& all_people($limit); // This is your query again, it is for grabbing just one page worth of rows by applying $limit $paginationCtrls = ''; // Establish the $paginationCtrls variable if ($last != 1) { // If there is more than 1 page worth of results if ($pagenum > 1) { /* First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page. */ $previous = $pagenum - 1; $paginationCtrls .= '<a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"><span class="glyphicon glyphicon-backward"></a> '; for ($i = $pagenum - 4; $i < $pagenum; $i++) { // Render clickable number links that should appear on the left of the target page number if ($i > 0) { $paginationCtrls .= '<a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $i . '">' . $i . '</a> '; } }