Reputation:
I created my first successful pagination script following an online tutorial. Here it is:
<?php
include 'core/database/connect.php';
$per_page = 6;
$pages_query = mysql_query("SELECT COUNT(`user_id`) FROM `users`");
$pages = ceil(mysql_result($pages_query, 0) / $per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
$query = mysql_query("SELECT `username` FROM `users` WHERE `active` = 1 LIMIT $start, $per_page");
while ($query_row = mysql_fetch_assoc($query)) {
echo '<p>', $query_row['username'] , '</p>';
}
if ($pages >=1 && $page <=$pages) {
for ($x=1; $x<=$pages; $x++) {
echo ($x == $page) ? '<strong><a href="?page='.$x.'">'.$x.'</a></strong> ' : '<a href="?page='.$x.'">'.$x.'</a> ';
}
}
?>
My question is: How would I add a link LAST which moves the page to the very last one. FIRST is easy because the link always stays the same members.php?page=1 while the last should look something like... members.php?page=.$last or something of that sort. This is a very noob question but I am a noob programmer. Thanks in advance.
BTW there is no point for jsfiddle because there is no database we can connect to anyways.
Upvotes: 0
Views: 2265
Reputation: 105
Lint to last page is a link to page with max number. In your example this number store in var $pages So link look like
<strong><a href="?page='.$pages.'">last</a></strong>
Upvotes: 2