如何循环索引结果?使用php?

如何循环索引结果?使用php?,php,json,Php,Json,我得到了这个php代码,它从youtube的api中获取了一个播放列表并显示了视频,问题是我每次请求只能显示25个视频。我如何使我的php脚本有一个“加载更多”链接,该链接将请求另外25个视频,它可以重新加载页面或在同一页面中附加额外的结果,我只需要被指向正确的方向 我的代码: <?php $id = urlencode($_GET['id']); $url = "https://gdata.youtube.com/feeds/api/playlists/$id?alt=j

我得到了这个php代码,它从youtube的api中获取了一个播放列表并显示了视频,问题是我每次请求只能显示25个视频。我如何使我的php脚本有一个“加载更多”链接,该链接将请求另外25个视频,它可以重新加载页面或在同一页面中附加额外的结果,我只需要被指向正确的方向

我的代码:

<?php
    $id = urlencode($_GET['id']);
    $url = "https://gdata.youtube.com/feeds/api/playlists/$id?alt=jsonc&v=2&start-index=1
&max-results=25";
    $content = file_get_contents($url);
    $json = json_decode($content, true);
    echo "<div id=\"info\"><center><h1><b>{$json['data']['title']}</center></b></h1><br>{$json['data']['description']} there are {$json['data']['totalItems']} uploaded in this playlist.</center><p></div><div class=\"decoration\"></div>";
    echo "<div id=\"center\">";
    echo "<ul>";
    $count = 0;
    foreach ($json['data']['items'] as $items) {
        ++$count;
        echo "<li style=\"width: 300px;min-height: auto;border: none;display: inline-block;margin: 5px;padding:10px;background-color: rgba(17,0,52,0.14);border-radius: 5px;\"><a href=\"video.php?plid={$json['data']['id']}&vidid={$items['video']['id']}\"><font size=\"5\" style=\"font-weight:bold;\">{$items['video']['title']}</font></a><Br \>";
        echo "<a href=\"video.php?plid={$json['data']['id']}&vidid={$items['video']['id']}\"><img style=\"width:300;height:auto;\" src=\"{$items['video']['thumbnail']['hqDefault']}\" title=\"{$items['video']['title']}\" id=\"ytThumb\"></img></a></li>";
    }
echo "</ul>";
echo "</div>";
?>

使用
max results
时,您的tube只允许每个请求的
max 50
结果,因此如果您运行

$id = "UUpsSadsgX_Qk9i6i_bJoUwQ"; // for testing
$url = "https://gdata.youtube.com/feeds/api/playlists/$id?alt=jsonc&v=2&max-results=50";
$content = file_get_contents($url);
$json = json_decode($content, true);

echo "<div id=\"info\"><center><h1><b>{$json['data']['title']}</center></b></h1><br>{$json['data']['description']} there are {$json['data']['totalItems']} uploaded in this playlist.</center><p></div><div class=\"decoration\"></div>";
echo "<div id=\"center\">";
echo "<ul>";
$count = 0;
foreach ( $json['data']['items'] as $items ) {
    ++ $count;
    echo "<li style=\"width: 300px;min-height: auto;border: none;display: inline-block;margin: 5px;padding:10px;background-color: rgba(17,0,52,0.14);border-radius: 5px;\"><a href=\"video.php?plid={$json['data']['id']}&vidid={$items['video']['id']}\"><font size=\"5\" style=\"font-weight:bold;\">{$items['video']['title']}</font></a><Br \>";
    echo "<a href=\"video.php?plid={$json['data']['id']}&vidid={$items['video']['id']}\"><img style=\"width:300;height:auto;\" src=\"{$items['video']['thumbnail']['hqDefault']}\" title=\"{$items['video']['title']}\" id=\"ytThumb\"></img></a></li>";
}
echo "</ul>";
echo "</div>";


// you would get 50 results 

使用
max results
时,每个请求只允许
max 50
结果,因此如果运行

$id = "UUpsSadsgX_Qk9i6i_bJoUwQ"; // for testing
$url = "https://gdata.youtube.com/feeds/api/playlists/$id?alt=jsonc&v=2&max-results=50";
$content = file_get_contents($url);
$json = json_decode($content, true);

echo "<div id=\"info\"><center><h1><b>{$json['data']['title']}</center></b></h1><br>{$json['data']['description']} there are {$json['data']['totalItems']} uploaded in this playlist.</center><p></div><div class=\"decoration\"></div>";
echo "<div id=\"center\">";
echo "<ul>";
$count = 0;
foreach ( $json['data']['items'] as $items ) {
    ++ $count;
    echo "<li style=\"width: 300px;min-height: auto;border: none;display: inline-block;margin: 5px;padding:10px;background-color: rgba(17,0,52,0.14);border-radius: 5px;\"><a href=\"video.php?plid={$json['data']['id']}&vidid={$items['video']['id']}\"><font size=\"5\" style=\"font-weight:bold;\">{$items['video']['title']}</font></a><Br \>";
    echo "<a href=\"video.php?plid={$json['data']['id']}&vidid={$items['video']['id']}\"><img style=\"width:300;height:auto;\" src=\"{$items['video']['thumbnail']['hqDefault']}\" title=\"{$items['video']['title']}\" id=\"ytThumb\"></img></a></li>";
}
echo "</ul>";
echo "</div>";


// you would get 50 results 

那么,你自己尝试过实现这样一个解决方案吗?@MikeBrant我对php编程相当陌生,我读了一些东西,但这对我来说毫无意义,我不知道从哪里开始首先你必须问问自己。是否要在不重新加载页面的情况下执行此操作,或者是否正在重新加载页面。这是一个关键的决定,它将决定您需要使用什么技术(javascript/AJAX用于无页面laod或PHP,如果您想要页面加载)。youtube URL显然有一些参数可以更改,以改变最大结果数和开始的结果数。你只需要更改URL。@mikebrant我希望它不重新加载页面,但正如我所说,我对这种类型的编程相当陌生,所以如果这真的很复杂,那么我会选择更简单的方法,你有什么建议吗?那么你有没有自己尝试过实现这样一个解决方案?@MikeBrant我对php编程相当陌生,我读了一些东西,但对我来说没有意义,我不知道从哪里开始首先你必须问问自己。是否要在不重新加载页面的情况下执行此操作,或者是否正在重新加载页面。这是一个关键的决定,它将决定您需要使用什么技术(javascript/AJAX用于无页面laod或PHP,如果您想要页面加载)。youtube URL显然有一些参数可以更改,以改变最大结果数和开始的结果数。您只需更改该URL。@mikebrant我希望它不重新加载页面,但正如我所说,我对这种类型的编程相当陌生,所以如果这真的很复杂,那么我会选择更简单的方法,您有什么建议吗?我看到了开始索引和最大结果是如何工作的(尽管如此)我不知道最大结果达到50,我以为是25,但我如何回显一个链接,该链接将循环通过第1页、第2页、第3页等,它将显示索引=1、索引=2、索引=3的结果,etci查看开始索引和最大结果如何工作(尽管)我不知道最大结果达到50,我以为是25,但是我如何回传一个链接,它将在第1页、第2页、第3页等中循环,显示索引=1、索引=2、索引=3等的结果