i am looking for a very simple way to add a load more button to my json results, heres my code
// GET JSON DATA FOR TIMELINE
$UserTimeline = 'MYSITE/TimelineQuery.php?id='.$UserPageIDNum.'';
$TimelineContent = file_get_contents($UserTimeline);
$TimelineJson = json_decode($TimelineContent, true);
//OPEN FOREACH TIMELINE POSTS
foreach ($TimelineJson['data'] as $TimelineData)
{
if(isset($TimelineData['post']['TrackID'])){
echo $$TimelineData['post']['TrackID'];
}
}
What would be the simplest way to list the results to 5 and then press a load more button to load another 5 results and so on...
Thanks in advance!
In the code as shown here, your call to the PHP-routine would have an additional parameter: the starting-point, and possibly the maximum number of lines that should be returned. The server is to return that "slice" of lines.
The client remembers what starting-line it asked for previously, and how many lines it's asking for. The server should be designed to include line-numbers in its response. When a response comes back, the client merges the data into what data it already knows about, and notices if the maximum number of lines was returned. (If not, presumably the end-of-data has been reached.)
As usual, be very mindful of the fact that "this sort of thing has been done before, many times." Look, on GitHub and elsewhere, for any existing piece of code, on both the client and the server side, that you can ... so to speak ... "steal." :-)