-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle_playlist_liked_song.php
227 lines (198 loc) · 6.71 KB
/
single_playlist_liked_song.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
session_start();
include 'db_connection.php';
// Check if the database connection was successful
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Simulate user ID (replace with actual session/user ID)
$userID = $_SESSION["user_id"] ?? 1; // Ensure this is dynamically set based on session or user context
// Get playlist ID from query string
$playlistID = isset($_GET['playlist_id']) ? (int)$_GET['playlist_id'] : 0;
if ($playlistID === 0) {
die('Invalid playlist ID');
}
// Initialize playlist variable
$playlist = null;
// Fetch playlist details from the `playlists` table
$playlistQuery = $conn->prepare("SELECT * FROM playlists WHERE playlist_id = ?");
if (!$playlistQuery) {
die("Prepare failed: (" . $conn->errno . ") " . $conn->error);
}
$playlistQuery->bind_param("i", $playlistID);
$playlistQuery->execute();
$playlistResult = $playlistQuery->get_result();
if ($playlistResult->num_rows > 0) {
$playlist = $playlistResult->fetch_assoc();
} else {
// If not found in `playlists`, try the `playlist` table
$playlistQuery = $conn->prepare("SELECT * FROM playlist WHERE playlist_id = ?");
if (!$playlistQuery) {
die("Prepare failed: (" . $conn->errno . ") " . $conn->error);
}
$playlistQuery->bind_param("i", $playlistID);
$playlistQuery->execute();
$playlistResult = $playlistQuery->get_result();
if ($playlistResult->num_rows > 0) {
$playlist = $playlistResult->fetch_assoc();
}
}
$playlistQuery->close();
// Check if playlist is found
if (!$playlist) {
die('Playlist not found');
}
// Determine if this is the Liked Songs playlist
$isLikedSongs = ($playlist['playlist_name'] === 'Liked Songs');
// Fetch songs in the playlist
if ($isLikedSongs) {
$songsQuery = $conn->prepare("
SELECT songs.id, songs.song_title, artist.artist_name
FROM liked_songs
JOIN songs ON liked_songs.song_id = songs.id
JOIN artist ON songs.artist_id = artist.artist_id
WHERE liked_songs.user_id = ?
");
if (!$songsQuery) {
die("Prepare failed: (" . $conn->errno . ") " . $conn->error);
}
$songsQuery->bind_param("i", $userID);
} else {
$songsQuery = $conn->prepare("
SELECT songs.id, songs.song_title, artist.artist_name
FROM playlist_songs
JOIN songs ON playlist_songs.song_id = songs.id
JOIN artist ON songs.artist_id = artist.artist_id
WHERE playlist_songs.playlist_id = ?
");
if (!$songsQuery) {
die("Prepare failed: (" . $conn->errno . ") " . $conn->error);
}
$songsQuery->bind_param("i", $playlistID);
}
$songsQuery->execute();
$songs = $songsQuery->get_result()->fetch_all(MYSQLI_ASSOC);
$songsQuery->close();
mysqli_close($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($playlist['playlist_name']); ?></title>
<link rel="stylesheet" href="user_playlist.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap">
<style>
body {
font-family: 'Poppins', sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
background-image: url('assets/pic/background.png');
}
.playlist-container {
width: 80%;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
position: relative;
}
.close-button {
position: absolute;
top: 10px;
right: 10px;
font-size: 24px;
background: none;
border: none;
cursor: pointer;
outline: none;
}
.playlist-header {
display: flex;
align-items: center;
margin-bottom: 20px;
}
.playlist-image {
width: 150px;
height: 150px;
border-radius: 50%;
margin-right: 20px;
}
.playlist-details {
flex-grow: 1;
}
.playlist-details h1 {
margin: 0;
font-size: 24px;
font-weight: 600; /* Poppins weight 600 for bold text */
}
.playlist-details p {
margin: 5px 0 0;
color: #666;
}
.songs-list {
list-style: none;
padding: 0;
margin: 0;
}
.song-item {
display: flex;
align-items: flex-start; /* Align items at the start */
padding: 10px 0;
border-bottom: 1px solid #ddd;
}
.song-item a {
text-decoration: none;
color: inherit;
display: flex;
flex-direction: column; /* Stack title and artist vertically */
width: 100%;
}
.song-title {
font-size: 18px;
font-weight: 600; /* Poppins weight 600 for bold text */
margin-bottom: 5px; /* Space between title and artist */
}
.song-artist {
color: #666;
}
.song-item a:hover .song-title {
color: #007bff;
}
</style>
</head>
<body>
<div class="playlist-container">
<button class="close-button" onclick="goBack()">×</button>
<div class="playlist-header">
<img src="<?php echo htmlspecialchars($playlist['playlist_image']) ?: 'assets/pic/default.png'; ?>" alt="Playlist Image" class="playlist-image">
<div class="playlist-details">
<h1><?php echo htmlspecialchars($playlist['playlist_name']); ?></h1>
<p>Created on: <?php echo htmlspecialchars($playlist['created_at']); ?>, Total songs: <?php echo count($songs); ?></p>
</div>
</div>
<ul class="songs-list">
<?php if ($songs): ?>
<?php foreach ($songs as $song): ?>
<li class="song-item">
<a href="song_page.php?id=<?php echo urlencode($song['id']); ?>">
<span class="song-title"><?php echo htmlspecialchars($song['song_title']); ?></span>
<span class="song-artist"><?php echo htmlspecialchars($song['artist_name']); ?></span>
</a>
</li>
<?php endforeach; ?>
<?php else: ?>
<p>No songs found in this playlist.</p>
<?php endif; ?>
</ul>
</div>
<script>
function goBack() {
window.history.back();
}
</script>
</body>
</html>