-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcategories.php
More file actions
81 lines (74 loc) · 2.98 KB
/
Copy pathcategories.php
File metadata and controls
81 lines (74 loc) · 2.98 KB
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
<?php include 'templates/header.php';
// Randoming Image
function randomImage()
{
$images = glob('img/category/*');
return $images[rand(0, count($images) - 1)];
}
?>
<main class="container mt-4">
<h1 class="mb-4 text-center">All Category</h1>
<div class="row">
<?php
// Limiter Module
$batas = 6;
$halaman = isset($_GET['halaman']) ? (int)$_GET['halaman'] : 1;
$halaman_awal = ($halaman > 1) ? ($halaman * $batas) - $batas : 0;
// Page number
$previous = $halaman - 1;
$next = $halaman + 1;
// Get actual data
$sql = "SELECT id, name FROM category";
$data = mysqli_query($connect, $sql);
$jumlah_data = mysqli_num_rows($data);
$total_halaman = ceil($jumlah_data / $batas);
// Limitting Data
$query = "$sql limit $halaman_awal, $batas";
$categories = mysqli_query($connect, $query);
if (mysqli_num_rows($categories) > 0) {
foreach ($categories as $category) {
$excerpt = array_slice(explode(" ", $category['name']), 0, 15);
$excerpt = strip_tags(implode(' ', $excerpt)) . '...';
?>
<div class="col-md-4 mb-4">
<a href="index.php?c_id=<?= $category['id'] ?>&c_name=<?= $category['name'] ?>">
<div class="card overflow-hidden">
<img class="w-100" src="<?= randomImage() ?>" />
<div class="card-img-overlay d-flex align-items-end p-0">
<h5 class="card-title text-bg-dark text-center p-4 mb-0 flex-fill bg-opacity-75"><?= $category['name'] ?></h5>
</div>
</div>
</a>
</div>
<?php
}
?>
<!-- Pagination Module -->
<nav>
<ul class="pagination justify-content-center">
<li class="page-item">
<a class="page-link" <?php if ($halaman > 1) {
echo "href='?halaman=$previous'";
} ?>>Previous</a>
</li>
<?php
for ($x = 1; $x <= $total_halaman; $x++) {
?>
<li class="page-item"><a class="page-link" href="?halaman=<?= $x ?>"><?= $x; ?></a></li>
<?php
// var_dump($total_halaman);
}
?>
<li class="page-item">
<a class="page-link" <?php if ($halaman < $total_halaman) {
echo "href='?halaman=$next'";
} ?>>Next</a>
</li>
</ul>
</nav>
<?php
}
?>
</div>
</main>
<?php include 'templates/footer.php'; ?>