-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategory_page.php
More file actions
107 lines (83 loc) · 2.96 KB
/
category_page.php
File metadata and controls
107 lines (83 loc) · 2.96 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
include_once 'database.php';
include_once 'session.php';
// Function to fetch and display categories recursively
function displayCategories($conn, $parentDevice, $indent = 0)
{
// Fetch child categories
$sql_child = "SELECT DISTINCT device FROM categoriies WHERE parent_id = (SELECT id FROM categoriies WHERE device = '$parentDevice')";
$query_child = mysqli_query($conn, $sql_child);
while ($sub_row = mysqli_fetch_assoc($query_child)) {
$childDevice = $sub_row['device'];
echo "<li><a href='post_page.php?device=$childDevice' style='color: green; margin-left:" . ($indent * 30) . "px;'> →$childDevice</a></li>";
// Recursively display children of child categories
displayCategories($conn, $childDevice, $indent + 1);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Categories Page</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f8f9fa;
}
.container {
max-width: 600px;
margin: 50px auto;
background-color: #fff;
border-radius: 8px;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border: 2px solid #007bff;
}
h1,
h2 {
text-align: center;
}
ul {
list-style-type: none;
padding: 0;
}
li {
margin-bottom: 10px;
}
li a {
text-decoration: none;
color: #333;
font-weight: bold;
}
li a:hover {
color: black !important;
}
</style>
</head>
<body>
<div class="container">
<h1>Categories</h1>
<h2>Devices:</h2>
<ul>
<?php
// Fetch all parent categories
$sql = "SELECT DISTINCT device FROM categoriies WHERE parent_id = 0";
$query = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_assoc($query)) {
$parentDevice = $row['device'];
echo "<li><a href='post_page.php?device=$parentDevice' style='color: red;'> 🌚$parentDevice</a>";
// Call the recursive function to display child categories
echo "<ul>";
displayCategories($conn, $parentDevice, 1);
echo "</ul>";
echo "</li>";
}
?>
</ul>
</div>
</body>
</html>