I am trying to load content from my database 10 items at a time as the user scrolls through my web page. Right now I can load 10 items on scroll, but how can I load the next 10 items when they scroll more. Currently my php will grab the first 10 items each time, and my scroll function is only running once. I was looking at jscroll but was not really sure about its implimentation.
Here is my code, help appreciated.
PHP:
<?php // Create connection $con=mysqli_connect("localhost","root","","test"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM test"); $row = mysqli_fetch_array($result); for ($index=0; $index < 10; $index++) { echo '<table border="0" width="600px">'; echo "<tr>"; echo "<td><p>" . '<img src="' . $row['image'] . '" hspace="10" border="1" style="float:left;">' . "</p>"; echo "<p>" . "#" . $row['ID'] . ": " . $row['confession'] . "</p></td>"; echo "</tr>"; echo "</table>"; echo "<br>"; } mysqli_close($con); ?> JavaScript:
$(document).ready(function () { var flg='1'; $(window).scroll(function () { console.log($(document).scrollTop()); if ($(document).scrollTop() >299){ if(flg=='1') { $.post('test2.php', function(data) { $('#content').html(data); }); flg='0'; } } });});