-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
36 lines (27 loc) · 1.06 KB
/
index.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
<?php
require_once "Libraries/Pagination.php";
use Libraries\Pagination\Pagination;
// make sample data for test pagination for example i get data from database :))
$data = [];
for ($i = 1; 100 > $i; $i++) {
$text = md5("description $i");
$data[] = array(
["title" => "title $i", "description" => "description $text"],
);
}
$page = $_GET["page"] ?? 1; // current page number
$limit = $_GET["limit"] ?? 10; // limit is how many result showing per page
/** create Pagination instance and pass three required argument
* 1 @int count of your total data count
* 2 @int your current page number its by default set to 1
* 3 @int limit number of showing data per page its optional and by default set to ten|10
*/
$pagination = new Pagination(count($data), $page, $limit);
// using array_slice for showing real result like mysql from database ;)
$post = array_slice($data, $pagination->getOffset(), $limit);
// return object of paginate result
$paginate = $pagination->paginate();
echo json_encode(array(
"data" => $post,
"pagination" => $paginate,
));