繁体   English   中英

PHP分页-所有页面均显示在一页上

[英]PHP Pagination - All pages appearing on one page

我有下面的代码,问题是我试图让它分页。 我想要一个下拉菜单,您可以在其中选择要导航的页面。 现在,这段代码将所有页面显示在一页上(请参见此处的图片http://www.cfbangor.com/pagination.png )。 我将不胜感激任何完成此任务的指导。

 <?php // List all the videos in the KMC, a "page" at a time // // BUGS: Used $entry->dataUrl (original uploaded video) because $entry->downloadUrl doesn't work // for the default samples in the SaaS accounts.....! // Where are the downloadUrls for the default samples in the account? // Your Kaltura partner credentials define("PARTNER_ID", "xxxxxx"); define("ADMIN_SECRET", "yyyyyyyyyyyyyyyyyyyyyyyyyyy"); define("USER_SECRET", "zzzzzzzzzzzzzzzzzzzzzzzzzz"); require_once "KalturaClient.php"; $user = "SomeoneWeKnow"; $kconf = new KalturaConfiguration(PARTNER_ID); // If you want to use the API against your self-hosted CE, // go to your KMC and look at Settings -> Integration Settings to find your partner credentials // and add them above. Then insert the domain name of your CE below. // $kconf->serviceUrl = "http://www.mySelfHostedCEsite.com/"; $kclient = new KalturaClient($kconf); $ksession = $kclient->session->start(ADMIN_SECRET, $user, KalturaSessionType::ADMIN, PARTNER_ID); if (!isset($ksession)) { die("Could not establish Kaltura session. Please verify that you are using valid Kaltura partner credentials."); } $kclient->setKs($ksession); // Set the response format // KALTURA_SERVICE_FORMAT_JSON json // KALTURA_SERVICE_FORMAT_XML xml // KALTURA_SERVICE_FORMAT_PHP php $kconf->format = KalturaClientBase::KALTURA_SERVICE_FORMAT_PHP; $kfilter = new KalturaMediaEntryFilter(); $kfilter->mediaTypeEqual = KalturaMediaType::VIDEO; // Make sure video is done transcoding or whatever $kfilter->status = KalturaEntryStatus::READY; // List in descending order $kfilter->orderBy = KalturaBaseEntryOrderBy::CREATED_AT_DESC; // $kfilter->orderBy = KalturaBaseEntryOrderBy::CREATED_AT_ASC; // Create pager $pager = new KalturaFilterPager(); // choose the pageSize -- number of items per call // choose the pageIndex -- which page we're on now (page "1" is the first page) $pager->pageSize = 5; $pager->pageIndex = 1; echo "<h1>My Videos</h1>"; $result = $kclient->media->listAction($kfilter, $pager); $count = $result->totalCount; // total number of items in the account echo "<h1>Total: $result->totalCount Videos </h1>"; while (!empty($result->objects)) { echo "<h2>Page $pager->pageIndex</h2>"; echo "<table>"; foreach ($result->objects as $entry) { echo '<tr><td><img src="'.$entry->thumbnailUrl.'">&nbsp;&nbsp; Title: '.$entry->name.'&nbsp;&nbsp; <a href="'.$entry->dataUrl.'">download</a>&nbsp;&nbsp; Created on: '.date("DM j G:i:s TY", $entry->createdAt).'</td></tr>'; } echo "</table>"; $pager->pageIndex++; $result = $kclient->media->listAction($kfilter, $pager); } ?> 

您可以在一段时间内增加页码,并保持逐页渲染。

while (!empty($result->objects)) {
  echo "<h2>Page $pager->pageIndex</h2>";
  echo "<table>";
  ...
  echo "</table>";
  $pager->pageIndex++;
  $result = $kclient->media->listAction($kfilter, $pager);
}

您需要删除到while循环,仅呈现用户请求的一页。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM