<?php
header('Content-Type: application/json;', true);
header('Access-Control-Allow-Origin: *', true); ?>
{
<?php
include('connectDB.php');

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
}

$sql1 = "SELECT songs.ID, songs.title, songs.artist, songs.duration, songs.original_duration, songs.image, songs.id_subcat, SUBSTRING(path,4,150) as pathE, SUBSTRING_INDEX(SUBSTRING_INDEX(cue_times, '&sta=', -1), '&', 1) as cueStart, SUBSTRING_INDEX(SUBSTRING_INDEX(cue_times, '&int=', -1), '&', 1) as cueIntro FROM songs, multidiff WHERE songs.ID = multidiff.songID AND multidiff.slot = 'cdwall1'";
$result = mysqli_query($conn, $sql1);

if (mysqli_num_rows($result) > 0) {
  // output data of each row
  while($row = mysqli_fetch_assoc($result)) {
    echo "
                \"ID_1\": \"".utf8_encode($row["ID"]). "\",
                \"title_1\": \"".utf8_encode($row["title"]). "\",
                \"artist_1\": \"".utf8_encode($row["artist"]). "\",
                \"duration_1\": \"".gmdate("H:i:s.U", $row["duration"]). "\",
                \"origdur_1\": \"".gmdate("H:i:s", $row["original_duration"]). "\",
                \"image_1\": \"".utf8_encode($row["image"]). "\",
                \"cue_1\": \"".utf8_encode($row["cueStart"]). "\",
                \"intro_1\": \"".utf8_encode($row["cueIntro"]). "\",
                \"path_1\": \"".utf8_encode(str_replace('\\','%5C',$row["pathE"]))."\",
            ";
  }
} else {
  echo "0 results";
}



$sql2 = "SELECT songs.ID, songs.title, songs.artist, songs.duration, songs.original_duration, songs.image, songs.id_subcat, SUBSTRING(path,4,150) as pathE, SUBSTRING_INDEX(SUBSTRING_INDEX(cue_times, '&sta=', -1), '&', 1) as cueStart, SUBSTRING_INDEX(SUBSTRING_INDEX(cue_times, '&int=', -1), '&', 1) as cueIntro FROM songs, multidiff WHERE songs.ID = multidiff.songID AND multidiff.slot = 'cdwall2'";
$result = mysqli_query($conn, $sql2);

if (mysqli_num_rows($result) > 0) {
  // output data of each row
  while($row = mysqli_fetch_assoc($result)) {
    echo "
                \"ID_2\": \"".utf8_encode($row["ID"]). "\",
                \"title_2\": \"".utf8_encode($row["title"]). "\",
                \"artist_2\": \"".utf8_encode($row["artist"]). "\",
                \"duration_2\": \"".gmdate("H:i:s.U", $row["duration"]). "\",
                \"origdur_2\": \"".gmdate("H:i:s", $row["original_duration"]). "\",
                \"image_2\": \"".utf8_encode($row["image"]). "\",
                \"cue_2\": \"".utf8_encode($row["cueStart"]). "\",
                \"intro_2\": \"".utf8_encode($row["cueIntro"]). "\",
                \"path_2\": \"".utf8_encode(str_replace('\\','%5C',$row["pathE"]))."\",
            ";
  }
} else {
  echo "0 results";
}



$sql3 = "SELECT songs.ID, songs.title, songs.artist, songs.duration, songs.original_duration, songs.image, songs.id_subcat, SUBSTRING(path,4,150) as pathE, SUBSTRING_INDEX(SUBSTRING_INDEX(cue_times, '&sta=', -1), '&', 1) as cueStart, SUBSTRING_INDEX(SUBSTRING_INDEX(cue_times, '&int=', -1), '&', 1) as cueIntro FROM songs, multidiff WHERE songs.ID = multidiff.songID AND multidiff.slot = 'cdwall3'";
$result = mysqli_query($conn, $sql3);

if (mysqli_num_rows($result) > 0) {
  // output data of each row
  while($row = mysqli_fetch_assoc($result)) {
    echo "
                \"ID_3\": \"".utf8_encode($row["ID"]). "\",
                \"title_3\": \"".utf8_encode($row["title"]). "\",
                \"artist_3\": \"".utf8_encode($row["artist"]). "\",
                \"duration_3\": \"".gmdate("H:i:s.U", $row["duration"]). "\",
                \"origdur_3\": \"".gmdate("H:i:s", $row["original_duration"]). "\",
                \"image_3\": \"".utf8_encode($row["image"]). "\",
                \"cue_3\": \"".utf8_encode($row["cueStart"]). "\",
                \"intro_3\": \"".utf8_encode($row["cueIntro"]). "\",
                \"path_3\": \"".utf8_encode(str_replace('\\','%5C',$row["pathE"]))."\",
            ";
  }
} else {
  echo "0 results";
}



$sql4 = "SELECT songs.ID, songs.title, songs.artist, songs.duration, songs.original_duration, songs.image, songs.id_subcat, SUBSTRING(path,4,150) as pathE, SUBSTRING_INDEX(SUBSTRING_INDEX(cue_times, '&sta=', -1), '&', 1) as cueStart, SUBSTRING_INDEX(SUBSTRING_INDEX(cue_times, '&int=', -1), '&', 1) as cueIntro FROM songs, multidiff WHERE songs.ID = multidiff.songID AND multidiff.slot = 'cdwall4'";
$result = mysqli_query($conn, $sql4);

if (mysqli_num_rows($result) > 0) {
  // output data of each row
  while($row = mysqli_fetch_assoc($result)) {
    echo "
                \"ID_4\": \"".utf8_encode($row["ID"]). "\",
                \"title_4\": \"".utf8_encode($row["title"]). "\",
                \"artist_4\": \"".utf8_encode($row["artist"]). "\",
                \"duration_4\": \"".gmdate("H:i:s.U", $row["duration"]). "\",
                \"origdur_4\": \"".gmdate("H:i:s", $row["original_duration"]). "\",
                \"image_4\": \"".utf8_encode($row["image"]). "\",
                \"cue_4\": \"".utf8_encode($row["cueStart"]). "\",
                \"intro_4\": \"".utf8_encode($row["cueIntro"]). "\",
                \"path_4\": \"".utf8_encode(str_replace('\\','%5C',$row["pathE"]))."\",
            ";
  }
} else {
  echo "0 results";
}




$sql5 = "SELECT songs.ID, songs.title, songs.artist, songs.duration, songs.original_duration, SUBSTRING(path,4,150) as pathE, SUBSTRING_INDEX(SUBSTRING_INDEX(cue_times, '&sta=', -1), '&', 1) as cueStart, SUBSTRING_INDEX(SUBSTRING_INDEX(cue_times, '&int=', -1), '&', 1) as cueIntro FROM songs, multidiff WHERE songs.ID = multidiff.songID AND multidiff.slot = 'cart1'";
$result = mysqli_query($conn, $sql5);

if (mysqli_num_rows($result) > 0) {
  // output data of each row
  while($row = mysqli_fetch_assoc($result)) {
    echo "
                \"ID_5\": \"".utf8_encode($row["ID"]). "\",
                \"title_5\": \"".utf8_encode($row["title"]). "\",
                \"artist_5\": \"".utf8_encode($row["artist"]). "\",
                \"duration_5\": \"".gmdate("H:i:s.U", $row["duration"]). "\",
                \"origdur_5\": \"".gmdate("H:i:s", $row["original_duration"]). "\",
                \"cue_5\": \"".utf8_encode($row["cueStart"]). "\",
                \"intro_5\": \"".utf8_encode($row["cueIntro"]). "\",
                \"path_5\": \"".utf8_encode(str_replace('\\','%5C',$row["pathE"]))."\"
            ";
  }
} else {
  echo "0 results";
}

mysqli_close($conn);
?>
}
