-
Notifications
You must be signed in to change notification settings - Fork 1
/
paging.php
68 lines (58 loc) · 2.27 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
function paging_function($field, $thispage, $countsql){
include("connect_sql.php");
include_once("classes/develop_php_library.php"); // Include the class library
$per_page = 10; // number of results to show per page
$query3 = pg_query($db, $countsql);
$total_results = pg_num_rows($query3);
// echo $thispage;
// echo $total_results;
$total_pages = ceil($total_results / $per_page);//total pages we going to have
if (isset($_GET[$field])) {
$show_page = $_GET[$field]; //current page
if ($show_page > 0 && $show_page <= $total_pages) {
$start = ($show_page - 1) * $per_page;
$end = $start + $per_page;
} else {
// error - show first set of results
$show_page = 1;
$start = 0;
$end = $per_page;
}
} else {
// if page isn't set, show first set of results
$show_page = 1;
$start = 0;
$end = $per_page;
}
$pagLink = "<ul class=\"pagination pull-right\">";
if ($show_page>1){
$k = $show_page - 1;
$pagLink .= "<li><a href=$thispage?$field=".$k.">«</a></li>";
}
else {
$pagLink .= "<li class=\"disabled\"><a href=\"#\">«</a></li>";
}
if ($show_page - 5 > 0) $i = $show_page - 5;
else $i = 1;
if ($show_page + 5 < $total_pages) $end_page = $show_page + 5;
else $end_page = $total_pages;
for (; $i<=$end_page; $i++) {
if ($i == $show_page){
$pagLink .= "<li class=\"active\"><a href=$thispage?$field=".$i.">".$i."</a></li>";
}
else {
$pagLink .= "<li><a href=$thispage?$field=".$i.">".$i."</a></li>";
}
};
if ($show_page<$total_pages){
$k = $show_page + 1;
$pagLink .= "<li><a href=$thispage?$field=".$k.">»</a></li>";
}
else {
$pagLink .= "<li class=\"disabled\"><a href=\"#\">»</a></li>";
}
echo $pagLink . "</ul>";
return $countsql . " limit $per_page offset $start";
}
?>