I have an array $users
$statement = $pdo->prepare("SELECT * FROM activity");
$statement->execute();
$users = $statement->fetchAll();
and I display it like so
<?php
foreach ($users as $key => $row) {
$dist = 0.0;
$x1 = $lng;
$x2 = $row['alng'];
$y1 = $lat;
$y2 = $row['alat'];
$dist = acos(sin($x1=deg2rad($x1))*sin($x2=deg2rad($x2))+cos($x1)*cos($x2)*cos(deg2rad($y2) - deg2rad($y1)))*(6378.137);
$distn = FLOOR ( ROUND($dist,1) * 2 ) / 2 ; //calculate distn
$users[$key]['dist'] = $distn; //add dist to array foreach value
}
array_multisort(array_column($users, 'dist'), SORT_ASC, $users); / sort array with dist
foreach($users as $row) {
?>
<article class="mainusers" id="actvtar">
<div class="actvtinfo">
<a class="actvtsnm" href="actvt.php?id=<?php echo ($row['aid']);?>"><?php echo $row['title']; ?></a>
</div>
<a class="titlepic" href="actvt.php?id=<?php echo ($row['aid']);?>">
<img class="actvtpb" src="./activitys/<?php echo ($row['title']); ?>/activitypic.jpg" alt="Bild nicht gefunden" onerror="this.src='./img/no_title.png';"></img>
</a>
<div class="actvtfooter">
<p id="ua">Tags:</p>
<p class="tags" id="actvttags" name="interest"><?php echo $row['interest'];?></p>
<p id="actvtsdist"><?php echo $row['dist']; ?>km entfernt</p>
</div>
</article>
<?php }
?>
Now I want that the foreach loop is shown 5 times (5 items) and if I scroll to the bottom the next 5 are loaded. Just like Twitter, Instagram etc... How can I do that? I would appreciate it if you wouldnt mark this as duplicated because I searched for days now and I couldnt find an answear! Thanks for your help and have a great day :)