-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpagination.php
86 lines (52 loc) · 1.61 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
$dbname = 'eduplus1';
$host = '127.0.0.1';
$pass = '';
$user = 'root';
$pdoo = new PDO("mysql:host=$host;dbname=$dbname",$user,$pass);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
define('PER_PAGE', 3);
function results($page, $per_page, $pdo){
$begi = ($page - 1) * $per_page;
$per_page = $per_page;
$sql = 'SELECT * FROM class LIMIT '.$begi.', '.$per_page.'';
$stmt = $pdo->prepare($sql);
$stmt->execute();
$x = 1;
while($row = $stmt->fetch()){
echo '<tr>';
echo '<td>'.$x.'</td>';
echo '<td>'.$row['name'] . '</td>';
echo '</tr>';
$x++;
}
}
?>
<table >
<thead>
<th>s/n</th>
<th>class</th>
</thead>
<tbody>
<?php
results($page, PER_PAGE, $pdoo);
?>
</tbody>
</table>
<?php
$sql2 = 'SELECT count(id) as tot FROM class';
$st = $pdoo->prepare($sql2);
$st->execute();
$res = $st->fetch();
$total_p = ceil($res['tot'] / PER_PAGE);
$i = 1;
$value = '';
while($i <= $total_p){
$value .= "<a href='?page=".$i."'>".$i."</a> ";
++$i;
}
echo $page == 1 ? null : "<a href='?page=".--$page."'>Prev</a> ";
echo $value;
$p = (isset($_GET['page'])) ? $_GET['page'] : 1;
echo $p >= $total_p ? null : "<a href='?page=" . ( $p + 1 ) . "'>Next</a> ";
?>