This repository was archived by the owner on Jun 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpagination.php
64 lines (59 loc) · 1.97 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
<?php
include_once 'gestoria/constants.php';
include_once 'gestoria/Db.php';
include_once "gestoria/vendor/autoload.php";
const PAGE = "?page=";
$db = DB::getInstance();
$total_procedures = $db->get_scalar("select count(id) from wp_procedure");
$items_per_page = 5;
$total_pages = ceil($total_procedures / $items_per_page);
$current_page = 1;
if (array_key_exists("page", $_GET)) {
$current_page = filter_var($_GET["page"], FILTER_SANITIZE_NUMBER_INT);
}
$offset = ($current_page - 1) * $items_per_page;
echo "<br/> total pages: " . $total_pages;
echo "<br/> Current page: " . $current_page;
echo "<br/>total procedures: " . $total_procedures;
echo "<br/> offset: " . $offset;
try {
$procedures = $db->get_query("SELECT * FROM wp_procedure ORDER BY creation_date LIMIT :start, :end",
["start" => $offset, "end" => $items_per_page]);
krumo($procedures);
} catch (Exception $e) {
echo $e->getMessage();
}
?>
<!doctype html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=1080, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Pagination</title>
</head>
<body>
<ul>
<?php foreach ($procedures["data"] as $row): ?>
<li><strong><?= $row["id"]; ?></strong> <?= $row["creation_date"]; ?></li>
<?php endforeach; ?>
</ul>
<table>
<caption>Sonarlint is annoying</caption>
<thead>
<tr>
<th scope="row" colspan="4">Title</th>
</tr>
</thead>
<tr>
<td><a href="<?= $_SERVER["PHP_SELF"] . "?page=1"; ?>">Primero</a></td>
<td>
<a href="<?= $_SERVER["PHP_SELF"] . PAGE . ($current_page - 1 < 1 ? 1 : $current_page - 1); ?>">anterior</a>
</td>
<td><a href="<?= $_SERVER["PHP_SELF"] . PAGE . ($current_page + 1); ?>">siguiente</a></td>
<td><a href="<?= $_SERVER["PHP_SELF"] . PAGE . ($total_pages); ?>">ultimo</a></td>
</tr>
</table>
</body>
</html>