top10.php

View the content of the Karaoke-Version sample "top10.php", download the file and view its result after execution.

Download file
FileResult
<?php

require_once(__DIR__ . '/KVService.php');

// Query to get the Top 10 Songs
$top10Query = array(
    "function" => "list",
    "parameters" => array(
        "limit" => 10
    )
);
// Get the songs back form the service
$top10 = KVService::querySong($top10Query);

header("Content-Type: text/html; charset=UTF-8");
// Display the top
echo '<h1>Top 10 Songs</h1>';
echo "<ol>";
foreach ($top10->songs as $song) {
    // Get the artist of the song
    $queryArtist = array(
        "function" => "get",
        "parameters" => array("id" => $song->artistId)
    );
    $artist = KVService::queryArtist($queryArtist)->artist;
    echo '<li>
            <a href="' . $song->url . '">' . $artist->name . ' - ' . $song->name . '</a> | <a href="' . $song->previewUrl . '">Preview</a>
          </li>';
}
echo "</ol>";