prepare('SELECT COUNT(*) FROM friend_requests WHERE (rid = :u) AND valid = 1'); $total->bindParam(":u", $GLOBALS['user']->id, PDO::PARAM_INT); $total->execute(); $total = $total->fetchColumn(); // How many items to list per page $limit = 18; // How many pages will there be $pages = ceil($total / $limit); // What page are we currently on? $page = min($pages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array( 'options' => array( 'default' => 1, 'min_range' => 1, ), ))); // Calculate the offset for the query $offset = ($page - 1) * $limit; // Some information to display to the user $start = $offset + 1; $end = min(($offset + $limit), $total); // Prepare the paged query $stmt = $pdo->prepare('SELECT * FROM friend_requests WHERE (rid = :u) AND valid = 1 ORDER BY whenSent DESC LIMIT :limit OFFSET :offset'); // Bind the query params $stmt->bindParam(":u", $GLOBALS['user']->id, PDO::PARAM_INT); $stmt->bindParam(':limit', $limit, PDO::PARAM_INT); $stmt->bindParam(':offset', $offset, PDO::PARAM_INT); $stmt->execute(); // Do we have any results? if ($stmt->rowCount() > 0) { // Define how we want to fetch the results $stmt->setFetchMode(PDO::FETCH_ASSOC); $iterator = new IteratorIterator($stmt); foreach($iterator as $request) { $currentrequest = getUsername($request['sid']); $render = getPlayerRender($request['sid']); $friendrequest_html .= <<

{$currentrequest}

EOT; } } else { $friendrequest_html = "No friend requests"; } //page buttons handling { $beginning_button_html = ""; $pageback_html = ""; $currentpage_html = ""; $pageforward_html = ""; $last_button_html = ""; $pages_html = ""; if ($pages > 1) { $beginning_button_html = <<<< EOT; //page back $pageback = $page - 1; $pageback_html = <<‹ EOT; if ($pages > 5) //check if the page has more than 5 pages { //show the current page button $currentpage_html = <<$page EOT; $currentpages = 0; for($i=$page; $i<$pages; $i++) { $b=$i + 1; $currentpages = $currentpages + 1; if ($currentpages <= 4) //we want 5 buttons per page, but since gay we have the extra button above this loop { if ($page == $b) { $pages_html .= <<{$b} EOT; } else { $pages_html .= <<{$b} EOT; } } } } else { for($i=0; $i<$pages; $i++) { $b=$i + 1; if ($page == $b) { $pages_html .= <<{$b} EOT; } else { $pages_html .= <<{$b} EOT; } } } //page forward $pageforward = $page + 1; $pageforward_html = <<› EOT; $last_button_html = <<>> EOT; } if ($pages != 0) { if ($_GET['page'] == 0) { redirect("friend-requests?page=1"); } elseif ($_GET['page'] == $pages + 1) { redirect("friend-requests?page=".$pages.""); } } elseif ($pages == 0) { if (!$_GET['page']) { redirect("friend-requests?page=1"); } elseif($_GET['page'] > 1) { redirect("friend-requests?page=1"); } } $body = <<
Friend Requests ({$totalfriendrequests->rowCount()})
    {$friendrequest_html}
{$beginning_button_html} {$pageback_html} {$currentpage_html} {$pages_html} {$pageforward_html} {$last_button_html}
EOT; pageHandler(); $ph->body = $body; $ph->output(); ?>