<?php

   include "pdo_connection.php";

   $sql = "SELECT _9a_song.ID, _9a_song.Artist_ID, _9a_song.Title, _9a_arist.Name"
         ."  FROM _9a_song JOIN _9a_arist ON _9a_song.Artist_ID = _9a_arist.ID WHERE";

   $and = " ";

   if($_REQUEST["Artist_ID"] != 0) {
       $filters[] = "Artist_ID = ?";
       $values[] = $_REQUEST["Artist_ID"];
   } else {
       $filters[] = "Artist_ID > ?";
       $values[] = 0;
   }

   foreach ($filters as $filter) {
      $sql = $sql.$and.$filter;
      $and = " AND";
   }
   $stmt = $pdo->prepare($sql);
   $stmt->execute($values);

   if($stmt->rowCount() == 0) echo "No songs";
   else {
      $output = "";
      while ($row = $stmt->fetch()) {
         $output = $output.$row["ID"]."|".$row["Name"]."|".$row["Title"]."|".$row["Artist_ID"]."#";
      }
      echo trim($output, "#");
   }

?>