-
Notifications
You must be signed in to change notification settings - Fork 0
/
paging.php
46 lines (36 loc) · 1.17 KB
/
paging.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
echo "<ul class='pagination'>";
// button for first page
if($page>1){
echo "<li><a href='{$page_url}' title='Go to the first page.'>";
echo "First";
echo "</a></li>";
}
// calculate total pages
$total_pages = ceil($total_rows / $records_per_page);
// range of links to show
$range = 2;
// display links to 'range of pages' around 'current page'
$initial_num = $page - $range;
$condition_limit_num = ($page + $range) + 1;
for ($x=$initial_num; $x<$condition_limit_num; $x++) {
// be sure '$x is greater than 0' AND 'less than or equal to the $total_pages'
if (($x > 0) && ($x <= $total_pages)) {
// current page
if ($x == $page) {
echo "<li class='active'><a href=\"#\">$x <span class=\"sr-only\">(current)</span></a></li>";
}
// not current page
else {
echo "<li><a href='{$page_url}page=$x'>$x</a></li>";
}
}
}
// button for last page
if($page<$total_pages){
echo "<li><a href='" .$page_url. "page={$total_pages}' title='Last page is {$total_pages}.'>";
echo "Last";
echo "</a></li>";
}
echo "</ul>";
?>