-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnavbar.php
143 lines (126 loc) · 3.82 KB
/
navbar.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
// Include database connection and session management
include "dbconnection.php";
session_start();
// Check if the user is logged in
$is_logged_in = isset($_SESSION['user_id']);
?>
<!-- Navbar HTML -->
<div class="navbar">
<a href="index.php" class="logo">GameZone</a>
<div class="search-container">
<input
type="text"
id="game-search"
placeholder="Search Games or Playlists"
oninput="searchGames()"
/>
<div id="game-dropdown" class="dropdown"></div>
</div>
<?php if (!$is_logged_in): ?>
<a href="login.php" class="login-button">Login</a>
<?php endif; ?>
</div>
<!-- Inline CSS -->
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
}
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #333;
padding: 10px 20px;
color: white;
}
.navbar .logo {
text-decoration: none;
color: white;
font-size: 20px;
font-weight: bold;
}
.navbar .login-button, .navbar .profile-button {
color: white;
text-decoration: none;
background-color: #007BFF;
padding: 5px 10px;
border-radius: 5px;
font-size: 16px;
}
.navbar .login-button:hover, .navbar .profile-button:hover {
background-color: #0056b3;
}
.search-container {
position: relative;
}
#game-search {
padding: 5px 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
width: 250px;
}
.dropdown {
position: absolute;
top: 40px;
left: 0;
background: white;
border: 1px solid #ccc;
border-radius: 5px;
width: 100%;
max-height: 200px;
overflow-y: auto;
z-index: 1000;
display: none;
}
.dropdown .game-item {
padding: 10px;
cursor: pointer;
border-bottom: 1px solid #eee;
color: red;
}
.dropdown .game-item:hover {
background-color: #f0f0f0;
}
</style>
<!-- Inline JavaScript for Search -->
<script>
async function searchGames() {
const query = document.getElementById('game-search').value.trim();
const dropdown = document.getElementById('game-dropdown');
dropdown.innerHTML = ''; // Clear existing options
if (!query) {
dropdown.style.display = 'none';
return;
}
try {
const response = await fetch(`search_general.php?game=${encodeURIComponent(query)}`);
const results = await response.json();
if (results.length === 0) {
const noResults = document.createElement('div');
noResults.className = 'game-item';
noResults.textContent = 'No results found';
dropdown.appendChild(noResults);
} else {
results.forEach(item => {
const option = document.createElement('div');
option.className = 'game-item';
option.textContent = `${item.title} (${item.type === 'game' ? 'Game' : 'Playlist'})`;
option.onclick = () => {
if (item.type === 'game') {
window.location.href = `gamepage.php?game_id=${item.id}`;
} else if (item.type === 'playlist') {
window.location.href = `playlist_view.php?playlist_id=${item.id}`;
}
};
dropdown.appendChild(option);
});
}
dropdown.style.display = 'block';
} catch (error) {
console.error('Error fetching results:', error);
}
}
</script>