0

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?

Emma
  • 27,428
  • 11
  • 44
  • 69
RobertW
  • 156
  • 14
  • 1
    php's job is done after source html is loaded – Talal Apr 21 '19 at 17:44
  • 2
    Possible duplicate of [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – miken32 Apr 21 '19 at 17:58
  • 1
    To change page content on the go you'd probably want to jook into javascript, otherwise you can split it into pages and add an attribute that tells php which items to put on the page (`***/movies.php?startingitem=10`) – IcedLance Apr 21 '19 at 18:05

0 Answers0