-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
65 lines (55 loc) · 1.7 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nested navigation</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/js/all.min.js"></script>
<script src="./script.js" defer></script>
</head>
<body>
<div class="container">
<nav>
<div class="mobile-nav">
<span>Menu</span>
<div class="nav-btn">
<i class="fas fa-bars"></i>
</div>
</div>
<ul class="nav">
<?php
include 'db.class.php';
$obj = new Db;
$result = $obj->query('SELECT * from menu');
menu($result);
function menu($data, $parent_id=0){
foreach ($data as $key => $value) {
if ($value['parent'] == $parent_id) {
html($data, $value);
}
}
}
function html($data, $menu){
$count = 0;
foreach ($data as $key => $value) {
if ($value['parent'] == $menu['id']) {
$count++;
}
}
if ($count > 0) {
echo '<li class=dropdown><a href="#">'.ucfirst($menu['menu_name']).'</a><ul>';
menu($data, $menu['id']);
echo '</ul></li>';
}
else{
echo '<li><a href="#">'.ucfirst($menu['menu_name']).'</a></li>';
echo '';
}
}
?>
</ul>
</nav>
</div>
</body>
</html>