-
Notifications
You must be signed in to change notification settings - Fork 0
/
track.php
28 lines (25 loc) · 822 Bytes
/
track.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
<?php
/*
* Simple JSON generation from static array
* http://localhost/songs/track.php?album=1&song=1
*/
include_once './data.php';
// check if song id is posted as GET param
if (isset($_GET["album"]) && $_GET["album"] != "" && isset($_GET["song"]) && $_GET["song"] != "") {
$album_id = $_GET["album"];
$song_id = $_GET["song"];
// get the album
$album = array_key_exists($album_id, $album_tracks) ? $album_tracks[$album_id] : NULL;
if ($album != NULL) {
// album found
// get the song
$song = array_key_exists($song_id - 1, $album["songs"]) ? $album["songs"][$song_id - 1] : NULL;
$song["album_id"] = $album_id;
$song["album"] = $album["album"];
echo json_encode($song);
} else {
// no album found
echo "no album";
}
}
?>