-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pagination.php
executable file
·108 lines (21 loc) · 1.4 KB
/
Pagination.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
function get_current_page_name() {
$current_page_name = substr( $_SERVER["SCRIPT_NAME"], strrpos( $_SERVER["SCRIPT_NAME"],"/" ) + 1 );
return $current_page_name;
}
function set_pagination( $total_num_of_records_we_are_going_to_fetch, $num_of_results_per_page = 50 ) {
# $pagination() array is necessary for ( Pagination Bar )
$pagination['current_page_name'] = get_current_page_name(); # get_current_page_name() is a user-defined function
$pagination['first_page'] = 1;
$pagination['current_page'] = empty( $_GET['page'] ) ? 1 : $_GET['page']; # If current page is empty (have no value) then make it equals to 1
$pagination['next_page'] = $pagination['current_page'] + 1;
$pagination['previous_page'] = $pagination['current_page'] - 1;
$pagination['num_of_results_per_page'] = $num_of_results_per_page;
$pagination['start_record'] = ( $pagination['current_page'] - 1 ) * $pagination['num_of_results_per_page'];
# Determine last page number
$pagination['last_page'] = ceil( $total_num_of_records_we_are_going_to_fetch / $pagination['num_of_results_per_page'] );
# If there was no result then make the last page equals to 1
if ( $pagination['last_page'] == 0 ) { $pagination['last_page'] = 1; }
return $pagination;
}
?>