-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlimit-pages.php
42 lines (33 loc) · 1005 Bytes
/
limit-pages.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
<?php
require_once 'EasySQL.php';
$db = new EasySQL('localhost', 'Easy', 'root', '123456');
// Set up pagination parameters
$perPage = 10;
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$offset = ($page - 1) * $perPage;
// Define the conditions and options for the query
$conditions = array();
$options = array(
'LIMIT' => "$offset, $perPage"
);
// Perform the query and retrieve the results
$results = $db->select('users', '*', $conditions, $options);
// Count the total number of results
$totalResults = count($db->select('users'));
// Calculate the total number of pages
$totalPages = ceil($totalResults / $perPage);
// Output the results and pagination links
foreach ($results as $result) {
echo $result['id'] . ': ' . $result['name'] . '<br>';
}
echo '<br>';
if ($totalPages > 1) {
echo 'Pages: ';
for ($i = 1; $i <= $totalPages; $i++) {
if ($i == $page) {
echo "$i ";
} else {
echo "<a href=\"?page=$i\">$i</a> ";
}
}
}