artist_list.php

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

Download file
FileResult
<?php

require_once('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">&lt;&lt;</a>&nbsp;';
        echo '<a href="?page=' . ($curPage - 1) . '">&lt;</a>&nbsp;';
    }
    for ($i = $min; $i <= $max; $i++) {
        if ($i == $curPage)
            echo '<b>' . $i . '</b>';
        else
            echo '<a href="?page=' . $i . '">' . $i . '</a>';
        echo '&nbsp;';
    }
    if ($curPage < $totPages) {
        echo '<a href="?page=' . ($curPage + 1) . '">&gt;</a>&nbsp;';
        echo '<a href="?page=' . $totPages . '">&gt;&gt;</a>&nbsp;';
    }
    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);