Currently, I have a page that displays all movies with their thumbnails in the current directory. To assist with load times, I'd like to pause the foreach
loop until "more" is clicked then load the next 20 pages on the same page, or split it into "page 1, 2, 3...".
I got started, then realized this is just running the foreach
20 times:
$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");
How do I solve this problem?