Infinite Scroll with PHP array

0

I have a PHP array with about 10,000 keys organized like this:

Array
(
    [0] => Array
        (
            [id] => 13154
            [photo_file] => 013154.jpg
        )

    [1] => Array
        (
            [id] => 7885
            [photo_file] => 007885.jpg
        )
)

And in the HTML file I have a loop that transforms the array into image tags like this:

<?php
  foreach ($array as $key => $value) {
    $photo_file = $array[$key]["photo_file"];
    echo "<img src='$photo_file' />";
?>

I wanted to create an Infinite Scroll from this PHP array to avoid loading all the images at once when the page was accessed. Any ideas on the best way to do this?

Maybe I could convert the PHP array to JSON and then to a Javascript variable to use JQuery?

    
asked by anonymous 21.04.2017 / 19:48

1 answer

0

You can load the entire array at once using ajax (maybe with jQuery), the php (server) would return the array encoded in json, the javascript would be in charge of listening to the onscroll event to display the content in the html. / p>

Or you can use another approach, where php does not return the entire array at once. But instead it gradually returns, for example, 10 indexes at a time. For this, the javascript client would have to send in the ajax request the last index accessed and the server would manipulate the rest.

    
21.04.2017 / 21:21