Continuous page load content PHP


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 // 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>

" . '<img src="' . $row['image'] . '" hspace="10" border="1" style="float:left;">' . "

"; echo "

" . "#" . $row['ID'] . ": " . $row['confession'] . "

</td>"; echo "</tr>"; echo "</table>"; echo "<br>"; } mysqli_close($con); ?>


$(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'; } } });});


You need to implement "pagination". This is basically an offset and a limit to fetch X rows starting at the offset. If you google for "php pagination tutorial" you'll find plenty of tutorials, <a href="http://www.phpfreaks.com/tutorial/basic-pagination" rel="nofollow">here is one of them</a>.

I think describing the whole concept here in detail with code examples would become a very long answer and there are plenty of tutorials, so just check them out.


You need to send a parameter to the server script telling it where to start from. You can then use ORDER BY and LIMIT to select the appropriate records in the database to add.


  • mysqli statement not displaying else for no result
  • Why is my php code not connecting to my remote MySql database?
  • Input my php in mysql without repeat?
  • display records in table
  • PHP retrieve records from database
  • How can I retrieve posts with featured images from a WordPress database if WordPress is no longer in
  • Warning: mysqli_close() expects parameter 1 to be mysqli
  • How to update a table from one server to another?
  • Unable to insert form data in MySQL database
  • Display json in html
  • INSERT multiple entries from Android -> PHP -> MYSQL
  • jquery ajax dont work without firebug break point
  • Passing data-* to bootstrap Modal
  • Sending POST request with data to PHP script from c# level
  • Using timeline Google Chart API in PHP - Date/Time formatting issues
  • How many people are registering in the day of the week
  • How to retrieve data from multiple tables using a PHP form?
  • PHP Database driven Multilevel Menu
  • PHP & MySQL - list query results under heading and subheading
  • PHP + MySQL - Autocomplete from database not getting data from table
  • PDO error when wrong host name
  • MYSQ & MVC3 SQL connection error \\ ProviderManifestToken but I am using MySQL
  • Moving mysql files across servers
  • How to check if every primary key value is being referenced as foreign key in another table
  • Display Images one by one with next and previous functionality
  • ORA-29908: missing primary invocation for ancillary operator
  • How to get next/previous record number?
  • align graphs with different xlab
  • Numpy divide by zero. Why?
  • php design question - will a Helper help here?
  • Unanticipated behavior
  • Comma separated Values
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • AngularJs get employee from factory
  • How do you join a server to an Active Directory (domain)?
  • How does Linux kernel interrupt the application?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • Can't mass-assign protected attributes when import data from csv file
  • Unable to use reactive element in my shiny app