Skip to content

Commit 4c3378c

Browse files
committed
add README
1 parent 22d4a73 commit 4c3378c

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

README.md

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

0 commit comments

Comments
 (0)