-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategory_items.php
More file actions
71 lines (63 loc) · 1.84 KB
/
Copy pathcategory_items.php
File metadata and controls
71 lines (63 loc) · 1.84 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
<!-- start header -->
<?php
$pageTitle = "Category";
include "./components/header.php";
?>
<!-- end header -->
<!-- category section -->
<section class="category_section layout_padding">
<div class="container">
<div class="heading_container">
<h2>
Category
</h2>
</div>
<div class="category_container">
<?php
require "./database/database.php";
$cacheKey = "homepage_categories";
$categories = [];
$fromCache = false;
if ($redis) {
$cachedData = $redis->get($cacheKey);
if ($cachedData) {
$categories = json_decode($cachedData, true);
$fromCache = true;
}
}
if (!$fromCache) {
$itemsList = "SELECT * FROM category;";
$items = mysqli_query($conn, $itemsList);
if ($items && $items->num_rows > 0) {
$categories = mysqli_fetch_all($items, MYSQLI_ASSOC);
if ($redis) {
$redis->setex($cacheKey, 3600, json_encode($categories));
}
}
}
if (count($categories) > 0) {
foreach ($categories as $item) {
echo '<div class="box">
<div class="img-box mb-3">
<a href="threads.php?id=' . $item['id'] . '">
<img src="./static/images/' . htmlspecialchars($item['image']) . '" alt="" height="130" width="130">
</a>
</div>
<div class="detail-box">
<a href="threads.php?id=' . $item['id'] . '" style="color:white;"><h5>
' . htmlspecialchars($item['heading']) . '
</h5></a>
</div>
</div>';
}
}
?>
</div>
</div>
</section>
<!-- end category section -->
<!-- start footer -->
<?php
include "./components/footer.php";
?>
<!-- end footer -->