Create Affiliate ID
Code samples below do not contain a valid Affiliate ID. Create an Affiliate account before using these.
Real sample code:
- PHP class to use our webservice View and download
- Top 10 View in action and download
- Search View in action and download
- Artist List View in action and download
Copied!
<?php
require_once(__DIR__ . '/KVService.php');
function displayJumpLinks($curPage, $nbResults, $totalLength)
{
echo '<p>';
$totPages = ceil($totalLength / $nbResults);
$min = ($curPage - 5) < 1 ? 1 : ($curPage - 5);
$max = ($curPage + 5) > $totPages ? $totPages : ($curPage + 5);
if ($curPage >= 2) {
echo '<a href="?page=1"><<</a> ';
echo '<a href="?page=' . ($curPage - 1) . '"><</a> ';
}
for ($i = $min; $i <= $max; $i++) {
if ($i == $curPage)
echo '<b>' . $i . '</b>';
else
echo '<a href="?page=' . $i . '">' . $i . '</a>';
echo ' ';
}
if ($curPage < $totPages) {
echo '<a href="?page=' . ($curPage + 1) . '">></a> ';
echo '<a href="?page=' . $totPages . '">>></a> ';
}
echo '</p>';
}
$page = isset($_GET["page"]) && ((int) $_GET["page"]) > 0 ? (int) $_GET["page"] : 1;
$start = $page - 1;
$nbResults = 15;
$offset = $start * $nbResults;
// Query to get the artist
$listQuery = array(
"function" => "list",
"parameters" => array(
"limit" => $nbResults,
"offset" => $offset
)
);
// Get the songs back form the service
$artists = KVService::queryArtist($listQuery);
header("Content-Type: text/html; charset=UTF-8");
// Display the top
echo '<h1>List of artists</h1>';
displayJumpLinks($page, $nbResults, $artists->totalLength);
if ($artists->length > 0) {
echo '<p>Display results <b>' . ($offset + 1) . '-' . ($offset + $artists->length) . '</b> on <b>' . $artists->totalLength . '.</b></p>';
echo '<ul>';
foreach ($artists->artists as $artist) {
echo '<li><a href="' . $artist->url . '">' . $artist->name . '</a></li>';
}
echo '</ul>';
} else {
echo '<p>No artists found.</p>';
}
displayJumpLinks($page, $nbResults, $artists->totalLength);