php - 暂停循环,直到使用 PHP 单击按钮
问题描述
目前,我有一个页面显示当前目录中的所有电影及其缩略图。为了帮助加载时间,我想暂停foreach
循环,直到单击“更多”,然后在同一页面上加载接下来的 20 页,或将其拆分为“第 1、2、3...”。
我开始了,然后意识到这只是运行了foreach
20 次:
$movies = glob('./*.{mp4,m4v}', GLOB_BRACE);
$images = glob('./*.{jpeg,jpg,png}', GLOB_BRACE);
$subtitles = glob('./*.{srt}', GLOB_BRACE); #To be used later.
$dir = $_SERVER['DOCUMENT_ROOT'];
$results = 0;
$resultsMax = 20;
echo file_get_contents($dir . "/html/header.html");
while ($results < $resultsMax) {
foreach ($images as $image) {
$lookup[pathinfo($image, PATHINFO_FILENAME)] = $image;
}
foreach ($movies as $movie) {
$image = $lookup[pathinfo($movie, PATHINFO_FILENAME)] ?? 'Temporary.jpg';
echo '<a href="' . $movie . '">
<img src="' . $image . '" style="width:300px;height:350px;border:0;">
</a>';
}
$results++;
}
echo file_get_contents($dir . "/html/footer.html");
我该如何解决这个问题?
解决方案
推荐阅读
- python - 在python中使用bs4从div中的后代标签中刮取
- python - 从 jupyter 笔记本中的进程更新小部件
- c++ - 为什么 Boost 的 QuickSort 比 Julia 的 QuickSort 慢?
- android - 无法在 child() Android Studio Firebase 中为参数“pathString”传递 null
- jira - 显示 Epic 中的子任务和相应故事的列表
- deployment - 将本地 hasura 添加到 Google 云运行时遇到问题
- github - 从 Azure 合并 GitHub 分支
- python - 为什么计划功能挂起,并且从不打印 csv?
- php - 数据库中的价格不适用于智能贝宝按钮
- c# - 如何获取 Cylance 用户 API 的访问令牌?