-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathindex.php
99 lines (93 loc) · 3.14 KB
/
index.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
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
include 'conn.php';
$limit = isset($_POST["limit-records"]) ? $_POST["limit-records"] : 5000;
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$start = ($page - 1) * $limit;
$result = $conn->query("SELECT * FROM customers LIMIT $start, $limit");
$customers = $result->fetch_all(MYSQLI_ASSOC);
$result1 = $conn->query("SELECT count(id) AS id FROM customers");
$custCount = $result1->fetch_all(MYSQLI_ASSOC);
$total = $custCount[0]['id'];
$pages = ceil( $total / $limit );
$Previous = $page - 1;
$Next = $page + 1;
?>
<!DOCTYPE html>
<html>
<head>
<title>Learn Web Coding > Pagination in PHP and MySQL </title>
<link rel="stylesheet" type="text/css" href="../library/css/bootstrap.min.css"/>
<script type="text/javascript" src="../library/js/jquery-3.2.1.min.js"></script>
</head>
<body>
<div class="container well">
<h1 class="text-center">Bootstrap Pagination in PHP and MySQL</h1>
<div class="row">
<div class="col-md-10">
<nav aria-label="Page navigation">
<ul class="pagination">
<li>
<a href="index.php?page=<?= $Previous; ?>" aria-label="Previous">
<span aria-hidden="true">« Previous</span>
</a>
</li>
<?php for($i = 1; $i<= $pages; $i++) : ?>
<li><a href="index.php?page=<?= $i; ?>"><?= $i; ?></a></li>
<?php endfor; ?>
<li>
<a href="index.php?page=<?= $Next; ?>" aria-label="Next">
<span aria-hidden="true">Next »</span>
</a>
</li>
</ul>
</nav>
</div>
<div class="text-center" style="margin-top: 20px; " class="col-md-2">
<form method="post" action="#">
<select name="limit-records" id="limit-records">
<option disabled="disabled" selected="selected">---Limit Records---</option>
<?php foreach([10,100,500,1000,5000] as $limit): ?>
<option <?php if( isset($_POST["limit-records"]) && $_POST["limit-records"] == $limit) echo "selected" ?> value="<?= $limit; ?>"><?= $limit; ?></option>
<?php endforeach; ?>
</select>
</form>
</div>
</div>
<div style="height: 600px; overflow-y: auto;">
<table id="" class="table table-striped table-bordered">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Mobile</th>
<th>Address</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php foreach($customers as $customer) : ?>
<tr>
<td><?= $customer['id']; ?></td>
<td><?= $customer['name']; ?></td>
<td><?= $customer['mobile']; ?></td>
<td><?= $customer['address']; ?></td>
<td><?= $customer['createdOn']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<div style="position: fixed; bottom: 10px; right: 10px; color: green;">
<strong>
Learn Web Coding
</strong>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#limit-records").change(function(){
$('form').submit();
})
})
</script>
</body>
</html>