Skip to content

Commit f5012a3

Browse files
committed
Merge pull request #1 from ha1t/add_example
add example.php
2 parents 710bfe5 + d1ca204 commit f5012a3

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

example.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
require_once __DIR__ . '/SimplePagination.php';
3+
4+
$db = [
5+
1 => ['id' => 1],
6+
2 => ['id' => 2],
7+
3 => ['id' => 3],
8+
4 => ['id' => 4],
9+
5 => ['id' => 5],
10+
6 => ['id' => 6],
11+
7 => ['id' => 7],
12+
8 => ['id' => 8],
13+
9 => ['id' => 9],
14+
];
15+
16+
$items = [];
17+
$current = (int)$_GET['page'];
18+
$count = 3;
19+
20+
if ($current === 1) {
21+
$items = [
22+
$db[1],
23+
$db[2],
24+
$db[3],
25+
$db[4],
26+
];
27+
} else if ($current === 2) {
28+
$items = [
29+
$db[4],
30+
$db[5],
31+
$db[6],
32+
$db[7],
33+
];
34+
} else if ($current === 3) {
35+
$items = [
36+
$db[7],
37+
$db[8],
38+
$db[9],
39+
];
40+
} else {
41+
$current = 1;
42+
$items = [
43+
$db[1],
44+
$db[2],
45+
$db[3],
46+
$db[4],
47+
];
48+
49+
}
50+
51+
$pagination = new SimplePagination($current, $count);
52+
$pagination->checkLastPage($items);
53+
54+
?>
55+
<html>
56+
<body>
57+
<h1>SimplePagination Example</h1>
58+
<?php if($pagination->current > 1): ?>
59+
<a href='?page=<?php echo $pagination->prev ?>'>Previous</a>
60+
<?php else: ?>
61+
Previous
62+
<?php endif ?>
63+
64+
<?php foreach ($items as $item): ?>
65+
<a href="<?php echo $item['id'] ?>"><?php echo $item['id'] ?></a>&nbsp;
66+
<?php endforeach ?>
67+
68+
<?php if(!$pagination->is_last_page): ?>
69+
<a href='?page=<?php echo $pagination->next ?>'>Next</a>
70+
<?php else: ?>
71+
Next
72+
<?php endif ?>
73+
</body>
74+
</html>

0 commit comments

Comments
 (0)